You are absolutely right, thank for finding this problem, Ian. With a sampling rate of 40000 the frequency seems right, but I'd like to take a look at the testings I did, and do the one I should have performed. (Not with any priority however.)
Markus Am 12.07.2011 23:13, schrieb Ian Clark: > Thank you for this, Markus. > It explains clearly the structure of a WAV file. For this I am very grateful. > > I've tried it on my Mac (OS 10.6.8) ... > > mywav440=: jpath'~addons/media/wav/freq440.wav' > mywav440 wav_write sinwav 440 2.0 8000 > > It certainly produces a tone. Unfortunately it is not the tone which > Audacity generates for frequency 440 (=A), nor Oleg's code in > media/wav, which agrees with that produced by Audacity. > I judge it is the octave above the D above A, instead of A itself. > > It is probably something to do with sampling rates. > When I have time, I shall compare the WAV files produced by your > program and Oleg's, byte-by-byte. > It would be nice to fix it, because your code is much clearer than > Oleg's, and easier to experiment with. > > Ian Clark > > > 2011/7/12 Markus Schmidt-Gröttrup<[email protected]>: > >> Am 12.07.2011 05:21, schrieb Ian Clark: >> >>> If I have a noun: 194.18 >>> (the value, in Hz, as it happens, of the 24th octave above the >>> "musical note" of the solar day... other planetary periods to be >>> substituted) >>> does anyone have a simple way of generating a brief audible tone of >>> that frequency? >>> >>> Mac or Unix please, not Win. >>> >>> Just a verb to emit the sound will be fine for now. Generating a WAV >>> file to play conventionally is a likely future requirement. >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >>> >>> >>> >> Some time ago I played around with wav-Files. >> A wav file could be created with >> >> 'freq194.wav' wav_write sinwav 194.18 2.0 8000 >> >> I have never testes it on a Mac or unix platform. >> Hope it is helpful. >> >> Markus >> >> >> NB. Evaluation of Microsoft WAV-Audio format >> NB. See http://ccrma.stanford.edu/courses/422/projects/WaveFormat >> wav_evaluate =: 3 : 0 >> d =: 1!:0<y >> if. 0=#d do. >> 'file does not exist : ',y >> else. >> t =: 'Evaluation for WAV-File: ',y >> t =:t,:'File size total : ',": 2{:: ,d >> r =: 1!:11 (y);0 44 >> t =:t, 'Chunk ID (expectd RIFF): ', 4{. r >> t =:t, 'ChunkSize : ', ":256#.|.a. i. 4{. 4}.r >> t =:t, 'Format (expected WAVE) : ', 4{. 8}.r >> t =:t, 'SubChunk1ID (exp fmt ) : ', 4{.12}.r >> t =:t, 'SubChunk1Size : ', ":256#.|.a. i. 4{.16}.r [ s =: 20+ >> 256#.|.a. i. 4{.16}.r >> t =:t, 'AudioFormat (exp 1=PCM): ', ":256#.|.a. i. 2{.20}.r >> t =:t, 'NumOfChannels : ',(":256#.|.a. i. >> 2{.22}.r),(<:256#.|.a. i. 2{.22}.r){' (Mono)',:' (Stereo)' >> t =:t, 'SampleRate : ', ":256#.|.a. i. 4{.24}.r >> t =:t, 'ByteRate : ', ":256#.|.a. i. 4{.28}.r >> t =:t, 'BlockAlign : ', ":256#.|.a. i. 2{.32}.r >> t =:t, 'BitsPerSample : ', ":256#.|.a. i. 2{.34}.r >> t =:t, 'SubChunk2 starts at : ', ":s >> t =:t, 'SubChunk2ID (exp data) : ', 4{. s}.r >> t =:t, 'SubChunk2Size : ', ":256#.|.a. i. 4{.(s+4)}.r >> end. >> ) >> >> NB. return _1 no such File, >> NB. _99 not RIFF, _98 not WAVE, _97 not PCM, _96 not data, _95 unknown >> parameter >> wav_read =: 3 : 0 >> d =: 1!:0<y NB. Datei anzeigen lassen >> if. 0=#d do. _1 return. end. >> r=. 1!:1<y NB. Datei lesen >> if. -.'RIFF' -: 4{. r do. _99 return. end. >> if. -.'WAVE' -: _4{. 12{.r do. _98 return. end. >> if. -. 1 -: 256#.|.a. i. _2{.22{.r do. _97 return. end. NB. PCM >> s =. 20+ 256#.|.a. i. _4{.20{.r NB. offset Subchunk2 >> if. 'data' ~: _4 {. r {.~ 4+s do. _96 return. end. >> nchannel =. 256#.|.a. i. _2{.24{.r >> bitssampl =. 256#.|.a. i. _2{.36{.r >> if. (nchannel=1)*.(bitssampl=8) do. >> a. i. (8+s)}. r >> elseif. (nchannel=2)*.(bitssampl=8) do. >> |: _2 ] \ a. i. (8+s)}. r >> elseif. (nchannel=1)*.(bitssampl=16) do. >> (]+ _65536&*@:(32767&<))+/"1 ]1 256 * "1 ] _2 ] \ a. i. (8+s)}. r >> elseif. (nchannel=2)*.(bitssampl=16) do. >> |:_2]\(]+ _65536&*@:(32767&<))+/"1 ] 1 256 *"1 ] _2 ] \ a. i. (8+s)}. r >> elseif. 1 do. >> _95 >> end. >> ) >> >> NB. Eine Glättung: plot 2 (%&2)@:+/\"1^:2 ] 4000{. "1 w >> >> >> NB. inverse umrechnung mit a. {~|.256 256 256 256#: nummer >> >> >> wav_header =: 3 : 0 >> t =: 'RIFF' >> t =: t, ,a. {~|.256 256 256 256#: 36+#y >> t =: t,'WAVE' >> t =: t,'fmt ' >> t =: t, ,a. {~|.256 256 256 256#: 16 >> t =: t, ,a. {~|. 256 256#: 1 >> t =: t, ,a. {~|. 256 256#: 1 >> t =: t, ,a. {~|.256 256 256 256#: 44100 >> t =: t, ,a. {~|.256 256 256 256#: 44100 >> t =: t, ,a. {~|. 256 256#: 1 >> t =: t, ,a. {~|. 256 256#: 8 >> t =: t,'data' >> t =: t, ,a. {~|.256 256 256 256#: #y >> ) >> >> NB. Umrechnung von Buchstaben-Note >> NB. y ist ein String mit Note wie: a b h c cis d es e f fis g as >> NB. x ist eine Oktavlage (Default: 0), negativ tiefer, positiv höher >> note2freq =: 3 : 0 >> n=.<;. _1' a ais h c cis d dis e f fis g gis b des es ges as' >> note =.'abcdefghisabcdefghis '{"0 1~'abcdefghisABCDEFGHIS'i."1 0 y >> scale =. 9 10 11 0 1 2 3 4 5 6 7 8 10 1 3 6 8 {~ n i.<,note >> freq =. (220 *2^%4)*(2^%12)^scale >> : >> (2^x)*note2freq y >> ) >> >> NB. creates a wave for y: freq, duration, sampling rate >> NB. scaling is between 1 and _1 >> sinwav =: 3 : 0 >> 'f d s'=. y >> 1 o. o. (2*f%s) * i.>.s*d >> ) >> >> NB. Normiert die Werte auf das in x angegebene Intervall und rundet >> NB. falls nur ein Wert angegeben ist der zweite Wert 0 >> norm =: 4 : 0 >> int =. (>./ ,<./ ) 2$x,0 >> maxmin =. (>./ ,<./ ) y >> quot =. (=/maxmin)+-/maxmin >> <.(0.5+({:int)-( ({:maxmin)*(-/int)%quot))+((-/int)%quot)*y >> ) >> >> NB. Maximum und Minimum von y >> extrema =:>./@, ,<./@, >> >> >> wav_write =: 4 : 0 >> ((wav_header y), (a. {~ 0 255 norm y)) overwrite<x >> ) >> >> tonreihe =: 3 : 0 >> , sinwav "1 y,"0 1 ] 0.25 44100 >> ) >> >> overwrite =: 4 : 0 >> if. 0<#1!:0 y do. 1!:55 y end. >> x 1!:2 y >> ) >> >> >> NB. creates a wave for y: freq, duration, sampling rate >> NB. scaling is between 1 and _1 >> sinwav =: 3 : 0 >> 'f d s'=. y >> 1 o. o. (2*f%s) * i.>.s*d >> ) >> >> >> NB. creates a wave for y: freq, duration, sampling rate, decline rate >> NB. scaling is between 1 and _1 >> decline_sinwav =: 3 : 0 >> 'f d s dc'=. y >> (^@*&(-dc) * 1&o.@*&(f*2p1)) (%s) * i.>.s*d >> ) >> >> NB. creates a wave for y: freq, duration, sampling rate, decline rate, >> vib-ampli, vib-freq >> NB. scaling is between 1 and _1 >> decline_vibwav =: 3 : 0 >> 'f d s dc a fm'=. y >> k =. i.>. s*d >> NB. (f)*^a*1 o.(2p1*fm%s)*k >> (^(-dc%s)*k)* 1 o.((f*2p1%s)*k) -a*1 o.(2p1*fm%s)*k >> ) >> NB. Beispiel e =: decline_vibwav 440 10 44100 0 10 8 >> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> >> > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
