|
Post by honkytonk on Aug 16, 2022 22:09:38 GMT
@ Rod: The goal is to know the number of tics for one minute that's good because the Windows recorder works in one-minute increments
@ tenochtitlanuk: Could you tell which lines you added and where
|
|
|
Post by tenochtitlanuk on Aug 17, 2022 8:55:37 GMT
This is the altered first part of Rod's code. Just a rushed version since I knew my wav file was 8-bit. Straightforward to scale other formats.
I don't exit cleanly- so expect an error message when quitting since I don't close a file. Easily corrected.
Rather occupied at present so not sure when I can play further!
filedialog "Open wav file", "*.wav", fileName$ open fileName$ for input as #wav 'the wavfileheader wav$ = Input$(#wav,lof(#wav)) print "ChunkID =";mid$(wav$,1,4) 'always RIFF print "ChunkSize =";value(mid$(wav$,5,4)) print "Format =";mid$(wav$,9,4) print "Sub1ID =";mid$(wav$,13,4) print "Sub1Size =";value(mid$(wav$,17,4)) print "AudioFormat =";value(mid$(wav$,21,2)) print "NumChannels =";value(mid$(wav$,23,2)) print "SampleRate =";value(mid$(wav$,25,4)) print "ByteRate =";value(mid$(wav$,29,4)) print "BlockAlign =";value(mid$(wav$,33,2)) print "bitPerSample=";value(mid$(wav$,35,2)) print "Sub2ID =";mid$(wav$,37,4) print "Sub2Size =";value(mid$(wav$,41,4)) print 'print "Sound Data"
WindowWidth =1200 WindowHeight =500
open "File display" for graphics_nsb as #fGr #fGr "trapclose quit" #fGr "fill darkblue ; color cyan ; goto 0 250 ; down"
open "audio.csv" for output as #fOut
minus1 =0 minus2 =0 for n= 0 to 200000 v =value( mid$( wav$, 45 +n, 1)) minus1 =v minus2 =minus1 'print v #fOut v ' save to csv file for spreadsheet if wanted vSmooth =( v +minus1 +minus2 ) /3 ' average present and previous two values ' soundwave swings up and down from centre 128 for 8 bit wav files. ' use abs to make + and - both positive, and scale/position on graph #fGr "goto "; int( n /100000 *1200); " "; 450 -2 *abs( ( vSmooth -128)) scan next
close #fOut wait
sub quit h$ close #h$ end end sub
|
|
|
Post by honkytonk on Aug 17, 2022 10:59:40 GMT
@ Rod: it looks like the "JB" code doesn't want to see more than 10 ticks While "Audacity" displays 26, all of the same amplitude. Several tests always give 9 or 10 tics Putting n = 40 does not change anything (of course). wave 26 tics here-->: libertybasic.fr/upload/the-wave.zip
|
|
|
Post by Rod on Aug 17, 2022 11:48:13 GMT
Ok, the first thing is that your sound file is HUGE! and there is no need. Take your file, use Audacity to make it Mono, 8000 Samples per second PCM.
That way you take your one minute file and reduce it from 10Mb of data to 400kb Also the data is simply 8bit data. one byte represents one sound sample, middle position (silence) is 127, 0 max low 255 max high.
This code averages 1000 bytes and charts it, your pings are still clearly shown even at this level of averaging. There may be mush faster and slicker ways to find the pings. But I will leave that to out gurus.
mid=127 sampos=45
WindowWidth = 800 WindowHeight = 600 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
nomainwin graphicbox #main.current, 130, 5, 630, 256 button #main.load,"Load",[load], UL, 5, 67, 90, 25 open "Sound Recording" for window as #main #main.current "down; fill darkgray; flush" #main "font ms_sans_serif 10" wait
[load] filedialog "Open As","*.wav",wave$ if wave$="" then wait gosub [chart] wait
[chart] xpos=0 print #main.current, "discard ;redraw ;down" open wave$ for binary as #live length=lof(#live) seek #live, sampos while eof(#live)=0 count=1000 avgsamp=0 while eof(#live)=0 and count>0 s=asc(input$(#live, 1)) avgsamp=avgsamp+abs(mid-s) count=count-1 wend avgsamp=avgsamp/1000 #main.current "color red ;size 1; line ";xpos;" ";0;" ";xpos;" ";avgsamp xpos=xpos+1 wend close #live return
[quit] close #main end
|
|
|
Post by honkytonk on Aug 17, 2022 12:34:33 GMT
In "Audacity" I did: "Stereo to Mono", then: "Resample" --> 8000; then: "Export audio". The file went from 10 MB --> 5.04 MB If I reload the processed file (5.04 MB) and do "resample" again, it says: 44100, your "sound 3" says: 8000 I didn't do the right thing?
EDIT: With your first code "JB" Sound Data "5.04 Mo" file: 250;255;249;255;247;255;251;255;248;255;1_ 0;0;0;7;0;7;0;10;0;5;0;4;0;253;255;248;255;246;255;239
Sound Data "son 3" (466 Ko) file: 128;127;128;127;128;126;125;125;125;125;125;125;125;125_ 125;125;125;125;125;125;125;125;125;125;125;125;125;_ 125;125;125;125
|
|
|
Post by Rod on Aug 17, 2022 14:43:20 GMT
Bottom left I chose project rate 8000 and on export I chose 8bit pcm encoding.
You should read a bit about how .wav files are built. But 8bit mono audio is all you need as each sound sample is one byte long. Any other format uses several bytes to store the sound sample and are much harder to parse.
|
|
|
Post by Rod on Aug 17, 2022 15:12:13 GMT
This is the MMI code I posted earlier tweaked to just listen to the Mic and show the sound sample. It is set for 8bit mono audio to reduce the data volume. I currently sample at 50ms you will need to experiment to see if that is sufficient to see the blips. Don't think an audio file is created but not sure how long it will run for. If it does use resource you would need to briefly stop and restart the stream.
'experimental Radiometer by rodbird@hotmail.com 'uses MMI to stream audio from Mic '8bit audio is set for faster parsing 'blips from giger counter are heard but 'need parsed, recorded and displayed 'currently samples at 50ms
nomainwin WindowWidth = 450 WindowHeight = 130 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) graphicbox #1.bar, 23, 50, 400, 20 open "Radiometer" for window_nf as #1 #1.bar "down; fill white; flush" #1.bar "backcolor green" #1 "trapclose [quit]"
[startRecording] 'set the .wav recording format bitspersample = 8 channels = 1 samplespersec = 8000 alignment = bitspersample * channels / 8 bytespersec = alignment * samplespersec
params$ = " bitspersample " + STR$(bitspersample)+_ " channels " + STR$(channels) +_ " alignment " + STR$(alignment) + _ " samplespersec " + STR$(samplespersec) + _ " bytespersec " + STR$(bytespersec)
'open wav audio to listen to the wavaudio r$=mciSendString$("open new type waveaudio alias wav") r$=mciSendString$("set wav "+params$)
timer 50, [readVolume] wait
[readVolume] #1.bar "discard ; backcolor white" #1.bar "boxfilled 400 25 ; backcolor green" r$=mciSendString$("status wav level") level = val(r$) 'print level #1.bar "boxfilled ";level;" 20; discard" wait
[quit] 'End the program timer 0 r$=mciSendString$("close wav") close #1 end
Function mciSendString$(s$) 'Buffer will contain a return string from 'the function, if there is one. buffer$=space$(1024)+chr$(0) calldll #winmm,"mciSendStringA",s$ as ptr,buffer$ as ptr,_ 1028 as long, 0 as long, r as long 'truncate returned string at null character buffer$=left$(buffer$, instr(buffer$, chr$(0)) - 1) if r>0 then mciSendString$="error" else mciSendString$=buffer$ end if End Function
|
|
|
Post by honkytonk on Aug 17, 2022 15:18:56 GMT
With the "Bottom" setting I went from 5.04 MB to -->: 1.83 MB
On export, there is only the metadata, no: "8 bits". My "Audacity" it's old (Windows XP 32bits)
|
|
|
Post by Rod on Aug 17, 2022 17:49:27 GMT
Export as .wav then in the save dialog chose 8bit pcm
|
|
|
Post by honkytonk on Aug 18, 2022 9:34:25 GMT
I searched all "Audacity", I couldn't find an "8 bit" setting nowhere.
I found a BF generator in "JB" which creates a ".wav" file (Code to put in a folder). But it's way too complex for my skill set for me to consider mixing it with your "viewer/recorder". I'm going to try anyway, I'm crazy... Code for interested specialists:
'initialisations 'fréquences générateur disponibles, Hertz F1=440: F2=1000: F3=2800 ' Ech1=11025 'fréquences d'échantillonnage disponibles ' Ech2=22050 ' Ech3=44100 'fréquences d'échantillonnage disponibles Ech1=8000 : Ech2=8000: Ech3=8000 'longueur souhaitée du fichier wav, secondes Long1=1: Long2=2: Long3=5 Volume=80 '0 à 100 pi=3.14159265 'potentiomètre de volume 'fond : X1Fond$="15":Y1Fond$="9": X2Fond$="35":Y2Fond$="111": fond$="black" 'glissière BasGliss=110: YMaxGliss=10 X1Gliss$="16":Y1Gliss$=str$(BasGliss-Volume) X2Gliss$="34":Y2Gliss$=str$(BasGliss) bande$="red" 'nomainwin 'taille fenêtre WindowWidth = 624: WindowHeight = 165 'boutons et contrôles groupbox #GenBF.gbx1, "Fréquence", 14, 11, 128, 115 radiobutton #GenBF.rdb1, str$(F1)+" Hz", [F1_On], [F1_Off], 30, 41, 104, 20 radiobutton #GenBF.rdb2, str$(F2)+" Hz", [F2_On], [F2_Off], 30, 66, 104, 20 radiobutton #GenBF.rdb3, str$(F3)+" Hz", [F3_On], [F2_Off], 30, 91, 104, 20 groupbox #GenBF.gbx2, "Echantillonnage", 150, 11, 120, 115 radiobutton #GenBF.rdb4, str$(Ech1)+" ech./s", [Ech1_On], [Ech1_Off], 166, 41, 98, 20 radiobutton #GenBF.rdb5, str$(Ech2)+" ech./s", [Ech2_On], [Ech1_Off], 166, 66, 98, 20 radiobutton #GenBF.rdb6, str$(Ech3)+" ech./s", [Ech3_On], [Ech1_Off], 166, 91, 98, 20 groupbox #GenBF.gbx3, "Durée", 278, 11, 104, 115 radiobutton #GenBF.rdb7, str$(Long1)+" s", [Duree1_On], [Duree1_off], 294, 41, 72, 20 radiobutton #GenBF.rdb8, str$(Long2)+" s", [Duree2_On], [Duree2_Off], 294, 66, 72, 20 radiobutton #GenBF.rdb9, str$(Long3)+" s", [Duree3_On], [Duree3_Off], 294, 91, 72, 20 graphicbox #GenBF.graf, 400, 8, 50, 120 statictext #GenBF.stx1, "Volume", 460, 45, 50, 25 statictext #GenBF.stx2, str$(Volume), 475, 65, 30, 25 'textbox #GenBF.txtb1, 425, 60, 50, 25 button #GenBF.btn1, "Créer", [Generateur], UL, 518, 26, 80, 80 open "Générateur BF" for window as #GenBF #GenBF, "font ms_sans_serif 0 16" #GenBF, "TRAPCLOSE [quit]" frequence=F1:print #GenBF.rdb1, "set" ech=Ech1:print #GenBF.rdb4, "set" duree=Long1:print #GenBF.rdb7, "set" gosub [dessin_Potar] #GenBF.graf, "when leftButtonUp [Choix_Volume]" wait '************************************************ [F1_On] frequence=F1:wait [F1_Off] wait [F2_On] frequence=F2:wait [F2_Off] wait [F3_On] frequence=F3:wait [F3_Off] wait [Ech1_On] ech=Ech1:wait [Ech1_Off] wait [Ech2_On] ech=Ech2:wait [Ech2_Off] wait [Ech3_On] ech=Ech3:wait [Ech3_Off] wait [Duree1_On] duree=Long1:wait [Duree1_off] wait [Duree2_On] duree=Long2:wait [Duree2_off] wait [Duree3_On] duree=Long3:wait [Duree3_off] wait [Choix_Volume] Y=MouseY if Y>BasGliss then Y=BasGliss 'dépassement vers le bas de l'écran if Y<YMaxGliss then Y=YMaxGliss 'YMaxGliss=10 Y1Gliss$=str$(Y) Volume=BasGliss-Y gosub [dessin_Potar] wait [dessin_Potar] 'fond du potentiomètre #GenBF.graf, "up" #GenBF.graf, "goto "+X1Fond$+" "+Y1Fond$+" " #GenBF.graf, "down" #GenBF.graf, "backcolor black" #GenBF.graf, "boxfilled "+X2Fond$+" "+Y2Fond$+" " 'couleur de la bande #GenBF.graf, "up" #GenBF.graf, "goto "+X1Gliss$+" "+Y1Gliss$+" " #GenBF.graf, "down" #GenBF.graf, "backcolor red" #GenBF.graf, "boxfilled "+X2Gliss$+" "+Y2Gliss$+" " 'mise à jour affichage numérique #GenBF.stx2, str$(Volume) return [Generateur] print print "Générateur :" print "fréquence = ";frequence print "fréquence d'échantillonnage = ";ech print "durée = ";duree print "volume = ";Volume pi=3.14159265: omega=2*pi*frequence: offset=127: delta=1/ech data$="" for t = 0 to duree step delta sample=(Volume/100)*sin(omega*t) yy=sample*offset data$=data$;chr$(int(yy+offset)) next t 'préparation de l'en-tête du fichier wave ChunkID$="RIFF" 'always RIFF ChunkSize$=makeAsciiNumber$(36+255,4) ' Format$="WAVE" 'always WAVE SubChunk1ID$="fmt " 'always "fmt " SubChunk1Size$=makeAsciiNumber$(16,4) 'size AudioFormat$=makeAsciiNumber$(1,2) ' NumChannels$=makeAsciiNumber$(1,2) SampleRate$=makeAsciiNumber$(ech,4) ByteRate$=makeAsciiNumber$(ech,4) BlockAlign$=makeAsciiNumber$(1,2) BitsPerSample$=makeAsciiNumber$(8,2) SubChunk2ID$="data" SubChunk2Size$=makeAsciiNumber$(len(data$),4) 'concaténation des données d'organisation dans la chaine wave$ wave$=ChunkID$;ChunkSize$;Format$;SubChunk1ID$;SubChunk1Size$;_ AudioFormat$;NumChannels$;SampleRate$;ByteRate$;BlockAlign$;_ BitsPerSample$;SubChunk2ID$;SubChunk2Size$ 'ajout des données audio wave$=wave$;data$ 'contrôle visuel que tout s'est bien passé, désactiver le nomainwin pour affichage ChunkID$=mid$(wave$,1,4) : print "ChunkID$:";ChunkID$ 'should be "RIFF" ChunkSize$=mid$(wave$,5,4) ChunkSize=bigAsciiNumber(ChunkSize$): print "ChunkSize$:";_ ChunkSize$,"ChunkSize:";ChunkSize,"File length:";len(wave$) Format$=mid$(wave$,9,4): print "Format$:";Format$ 'should be "WAVE" SubChunk1ID$=mid$(wave$,13,4): print "SubChunk1ID$:";SubChunk1ID$ 'should be "fmt " SubChunk1Size$=mid$(wave$,17,4) SubChunk1Size=bigAsciiNumber(SubChunk1Size$): print "SubChunk1Size$:";SubChunk1Size$,"SubChunk1Size:";SubChunk1Size AudioFormat$=mid$(wave$,21,2) AudioFormat=bigAsciiNumber(AudioFormat$): print "AudioFormat$:";AudioFormat$,"AudioFormat:";AudioFormat NumChannels$=mid$(wave$,23,2) NumChannels=bigAsciiNumber(NumChannels$): print "NumChannels$:";NumChannels$,"NumChannels:";NumChannels SampleRate$=mid$(wave$,25,4) SampleRate=bigAsciiNumber(SampleRate$): print "SampleRate$:";SampleRate$,"SampleRate:";SampleRate ByteRate$=mid$(wave$,29,4) ByteRate=bigAsciiNumber(ByteRate$): print "ByteRate$:";ByteRate$,"ByteRate:";ByteRate BlockAlign$=mid$(wave$,33,2) BlockAlign=bigAsciiNumber(BlockAlign$): print "BlockAlign$:";BlockAlign$,"BlockAlign:";BlockAlign BitsPerSample$=mid$(wave$,35,2) BitsPerSample=bigAsciiNumber(BitsPerSample$): print "BitsPerSample$:";BitsPerSample$,"BitsPerSample:";BitsPerSample 'data SubChunk2ID$=mid$(wave$,37,4): print "SubChunkID$:";SubChunkID$ 'should be "data" SubChunk2Size$=mid$(wave$,41,4) SubChunk2Size=bigAsciiNumber(SubChunk2Size$): print "SubChunk2Size$:";SubChunk2Size$,"SubChunk2Size:";SubChunk2Size 'saving wav file open "newwave2.wav" for output as #t #t wave$ close #t print :print "***** fichier créé ! ******" playwave "newwave2.wav" wait end function makeAsciiNumber$(number,length) 'makeAsciiNumber$(11025,4) 'admettons qu'on désire écrire 11025 sur 4 octets multiplier=256^(length-1) '256^(4-1) = 256^3 = 16777216 for i = length to 1 step -1 'de 4 à 1 par pas de -1 multiplier=256^(i-1) : if multiplier=0 then multiplier=1 'i=4 -> multiplier=256^3=16777216 'i=3 " =256^2=65536 'i=2 " =256^1=256 'i=1 " =256^0=1 asc=int(number/multiplier) 'i=4 -> asc=int(11025/16777216) =0,000657141208649 = 0 'i=3 " 11025/65536 =0,168228149414 = 0 'i=2 " 11025/256 =43,06640625 = 43 'i=1 " 17/1 =17 = 17 number=number-asc*multiplier 'i=4 -> number = 11025-0*16777216 = 11025 'i=3 " = 11025-0*65536 = 11025 'i=2 " = 11025-43*256 = 17 'i=1 " = 17-17*1 = 0 (???) 'on ajoute le caractère avant la chaine str$=chr$(asc);str$ 'print asc,chr$(asc),asc*multiplier,multiplier,number,,str$ next i makeAsciiNumber$=str$ end function function bigAsciiNumber(str$) multiplier=1 for i = 1 to 4 token$=mid$(str$,i,1) 'print token$,asc(token$),asc(token$)*multiplier,multiplier num=num+asc(token$)*multiplier multiplier=multiplier*256 next i bigAsciiNumber=num end function [quit] 'quitte le programme close #GenBF end
|
|
|
Post by Rod on Aug 18, 2022 15:34:45 GMT
How long is the time line? Do you need to record the audio or will the number of blips do? The .wav can be cycled, say every 60 seconds. Then analysed and the blip rate recorded. Will that suffice. The more you tell us about the project the better the advice.
My second Liberty solution just listened, no .wav to deal with.
|
|