creating wav's ?
Post by bluatigro on Dec 15th, 2016, 11:22am
i m trying to translate this c Code:
struct TWAVHeader
{
char rID[4]; // "RIFF"
dword rLen; // file size minus 8
char wID[4]; // "WAVE"
char fID[4]; // " fmt"
dword fLen; // 16
word FmtTag; // 1
word Channels; // 1 = Mono, 2 = Stereo
dword SampleRate; // 11025 = 11kHz, 22050 = 22 kHz, etc.
dword AvgBytesPerSec; // SampleRate*Channels*BitsPerSample/8
word BlockAlign; // Channels * BitsPerSample/8
word BitsPerSample; // 8, 16, etc.
char dID[4]; // "data"
dword dLen; // length in bytes of the sound buffer
};
int Amp=127;
float Fr=440*pow(2,(float)1/4);
char *Buf;
long BufSize=61440;
long SampleRate=11025;
void Generate()
{
for( long i=0; i255 ) Buf[i]=255;
else if( y<0 ) Buf[i] = 0;
else Buf[i] = y;
}
}
void main()
{
FILE *f;
TWAVHeader wh;
Buf = new char[BufSize];
Generate();
f = fopen("gen.wav","wb");
strcpy(wh.rID,"RIFF");
wh.rLen = sizeof(wh)+BufSize-8;
strcpy(wh.wID,"WAVE");
strcpy(wh.fID,"fmt ");
wh.fLen = 16;
wh.FmtTag = 1;
wh.Channels = 1;
wh.SampleRate = SampleRate;
wh.AvgBytesPerSec = SampleRate;
wh.BlockAlign = 1;
wh.BitsPerSample = 8;
strcpy(wh.dID,"data");
wh.dLen = BufSize;
fwrite(&wh,sizeof(wh),1,f);
fwrite(Buf,1,BufSize,f);
fclose(f);
delete Buf;
}
into Code:
''bluatigro 15 dec 2016
struct wavh
rID as char( 3 ) _ ''; // "RIFF"
rlen as ulong _ ''; // file size minus 8
wID as char( 3 ) _ ''; // "WAVE"
fID as char( 3 ) _ ''; // " fmt"
flen as ulong _ ''; // 16
word FmtTag; // 1
word Channels; // 1 = Mono, 2 = Stereo
SampleRate as ulong _''; // 11025 = 11kHz, 22050 = 22 kHz, etc.
AvgBytesPerSec as ulong _''; // SampleRate*Channels*BitsPerSample/8
word BlockAlign; // Channels * BitsPerSample/8
word BitsPerSample; // 8, 16, etc.
dID( 3 ) as ulong _''; // "data"
dlen as ulong ''; // length in bytes of the sound buffer
end type
samplerate = 11025
sec = 1
bufsize = samplerate * sec
fr = 440
dim buf( bufsize )
pi = atn( 1 ) * 4
for i = 0 to bufmax
buf(i) = sin( i * fr * pi * 2 / saplerate ) * 127 + 128
end sub
open "440_1000.wav" for output as #1
wh.rID "RIFF"
wh.rLen = sizeof(wh) + ( SampleRate * sec ) - 8
wh.wID = "WAVE"
wh.fID = "fmt "
wh.fLen = 16
wh.FmtTag = 1
wh.Channels = 1
wh.SampleRate = SampleRate
wh.AvgBytesPerSec = SampleRate
wh.BlockAlign = 1
wh.BitsPerSample = 8
wh.dID = "data"
wh.dLen = BufSize
fwrite(&wh,sizeof(wh),1,f);
fwrite(Buf,1,BufSize,f);
close #1
print "ready"
Re: creating wav's ?
Post by Richard Russell on Dec 15th, 2016, 1:59pm
on Dec 15th, 2016, 11:22am, bluatigro wrote:i m trying to translate this c |
|
Unfortunately LB/LBB won't let you do this:
Code: struct wavh, rID as char[4]
wavh.rID.struct = "RIFF"
It appears to work (neither LB nor LBB gives you an error message) but instead of the string "RIFF" being written to the structure what actually happens is that only "RIF" is written. You can confirm it as follows:
Code: struct wavh, rID as char[4]
wavh.rID.struct = "RIFF"
print wavh.struct
The reason it doesn't work as you would hope is that the CHAR[] structure member type in LB and LBB contains a NUL-terminated string, so char[4] has room only for a 3-character string plus the NUL.
As a result of this limitation you have to cheat slightly to get the string "RIFF" (without a NUL-termination) into the struct. The way to do it is as follows:
Code: struct wavh, rID as ulong
wavh.rID.struct = hexdec("46464952") ' "RIFF"
You can extend that technique to create the entire WAV header struct correctly. Here is the complete translated program to generate 1 second of 440 Hz tone (only 8-bits per sample so the quality isn't great):
Code: struct wavh,_
rID as ulong, _ ' "RIFF"
rLen as ulong, _ ' file size minus 8
wID as ulong, _ ' "WAVE"
fID as ulong, _ ' "fmt "
fLen as ulong, _ ' 16
FmtTag as word, _ ' 1
Channels as word, _ ' 1 = Mono, 2 = Stereo
SampleRate as ulong, _ ' 11025 = 11kHz, 22050 = 22 kHz, etc.
AvgBytesPerSec as ulong, _ ' SampleRate*Channels*BitsPerSample/8
BlockAlign as word,_ ' Channels * BitsPerSample/8
BitsPerSample as word,_ ' 8, 16, etc.
dID as ulong,_ ' "data"
dLen as ulong ' length in bytes of the sound buffer
wavh.rID.struct = hexdec("46464952") ' "RIFF"
wavh.wID.struct = hexdec("45564157") ' "WAVE"
wavh.fID.struct = hexdec("20746D66") ' "fmt "
wavh.dID.struct = hexdec("61746164") ' "data"
samplerate = 11025
sec = 1
bufsize = samplerate * sec
fr = 440
wavh.rLen.struct = len(wavh.struct) + bufsize - 8
wavh.fLen.struct = 16
wavh.FmtTag.struct = 1
wavh.Channels.struct = 1 ' Mono
wavh.SampleRate.struct = samplerate
wavh.BitsPerSample.struct = 8
wavh.AvgBytesPerSec.struct = wavh.SampleRate.struct * _
wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.BlockAlign.struct = wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.dLen.struct = bufsize
pi = atn( 1 ) * 4
open "440_1000.wav" for output as #1
print #1, wavh.struct;
for i = 1 to bufsize
print #1, chr$(sin( i * fr * pi * 2 / samplerate ) * 127 + 128);
next
close #1
playwave "440_1000.wav"
print "Ready"
end
This runs in both LB4 and LBB.
Richard.
Re: creating wav's ?
Post by bluatigro on Dec 16th, 2016, 10:48am
@ richard :
thanks for info
update :
FIRST MUZIK
Code:
struct wavh,_
rID as ulong, _ ' "RIFF"
rLen as ulong, _ ' file size minus 8
wID as ulong, _ ' "WAVE"
fID as ulong, _ ' "fmt "
fLen as ulong, _ ' 16
FmtTag as word, _ ' 1
Channels as word, _ ' 1 = Mono, 2 = Stereo
SampleRate as ulong, _ ' 11025 = 11kHz, 22050 = 22 kHz, etc.
AvgBytesPerSec as ulong, _ ' SampleRate*Channels*BitsPerSample/8
BlockAlign as word,_ ' Channels * BitsPerSample/8
BitsPerSample as word,_ ' 8, 16, etc.
dID as ulong,_ ' "data"
dLen as ulong ' length in bytes of the sound buffer
wavh.rID.struct = hexdec("46464952") ' "RIFF"
wavh.wID.struct = hexdec("45564157") ' "WAVE"
wavh.fID.struct = hexdec("20746D66") ' "fmt "
wavh.dID.struct = hexdec("61746164") ' "data"
samplerate = 11025
sec = 1 / 8
bufsize = samplerate * sec
for okt = 0 to 4
for note = 0 to 7
fr = hz( okt , note )
wavh.rLen.struct = len(wavh.struct) + bufsize - 8
wavh.fLen.struct = 16
wavh.FmtTag.struct = 1
wavh.Channels.struct = 1 ' Mono
wavh.SampleRate.struct = samplerate
wavh.BitsPerSample.struct = 8
wavh.AvgBytesPerSec.struct = wavh.SampleRate.struct * _
wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.BlockAlign.struct = wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.dLen.struct = bufsize
pi = atn( 1 ) * 4
open "wav\"+str$(fr)+".wav" for output as #1
print #1, wavh.struct;
for i = 1 to bufsize
print #1, chr$(sin( i * fr * pi * 2 / samplerate ) * 127 + 128);
next
close #1
next note
next okt
call play "c3 d3 e3 c3 c3 d3 e3 c3"
print "Ready"
end
function hz( okt , note )
hz = int( 55 * 2 ^ ( okt + note / 8 ) )
end function
sub playnote okt , note$
note = instr( "abcdefg" , note$ )
print "playing " ; okt ; " " ; note$
playwave "wav\"+str$(hz(okt,note))+".wav"
end sub
sub play muzik$
i = 1
while word$( muzik$ , i ) <> ""
q$ = word$( muzik$ , i )
note$ = left$( q$ , 1 )
okt = val( right$( q$ , 1 ) )
call playnote okt , note$
i = i + 1
wend
end sub
how do i do this whit 16 bit muzik ?
Re: creating wav's ?
Post by bluatigro on Dec 16th, 2016, 11:03am
update :
added #
Code:
struct wavh,_
rID as ulong, _ ' "RIFF"
rLen as ulong, _ ' file size minus 8
wID as ulong, _ ' "WAVE"
fID as ulong, _ ' "fmt "
fLen as ulong, _ ' 16
FmtTag as word, _ ' 1
Channels as word, _ ' 1 = Mono, 2 = Stereo
SampleRate as ulong, _ ' 11025 = 11kHz, 22050 = 22 kHz, etc.
AvgBytesPerSec as ulong, _ ' SampleRate*Channels*BitsPerSample/8
BlockAlign as word,_ ' Channels * BitsPerSample/8
BitsPerSample as word,_ ' 8, 16, etc.
dID as ulong,_ ' "data"
dLen as ulong ' length in bytes of the sound buffer
wavh.rID.struct = hexdec("46464952") ' "RIFF"
wavh.wID.struct = hexdec("45564157") ' "WAVE"
wavh.fID.struct = hexdec("20746D66") ' "fmt "
wavh.dID.struct = hexdec("61746164") ' "data"
samplerate = 11025
sec = 1 / 8
bufsize = samplerate * sec
for okt = 0 to 4
for note = 0 to 13
fr = hz( okt , note )
wavh.rLen.struct = len(wavh.struct) + bufsize - 8
wavh.fLen.struct = 16
wavh.FmtTag.struct = 1
wavh.Channels.struct = 1 ' Mono
wavh.SampleRate.struct = samplerate
wavh.BitsPerSample.struct = 8
wavh.AvgBytesPerSec.struct = wavh.SampleRate.struct * _
wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.BlockAlign.struct = wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.dLen.struct = bufsize
pi = atn( 1 ) * 4
open "wav\"+str$(fr)+".wav" for output as #1
print #1, wavh.struct;
for i = 1 to bufsize
print #1, chr$(sin( i * fr * pi * 2 / samplerate ) * 127 + 128);
next
close #1
next note
next okt
call play "c3 d3 e3 c3 c3 d3 e3 c3"
print "Ready"
end
function hz( okt , note )
hz = int( 55 * 2 ^ ( okt + note / 16 ) )
end function
sub playnote okt , note$
note = ( instr( "a a#b b#c c#d d#e e#f f#g g#" , note$ ) - 1 ) / 2
print "playing " ; okt ; " " ; note$
playwave "wav\"+str$(hz(okt,note))+".wav"
end sub
sub play muzik$
i = 1
while word$( muzik$ , i ) <> ""
q$ = word$( muzik$ , i )
note$ = left$( q$ , len( q$ ) - 1 )
okt = val( right$( q$ , 1 ) )
call playnote okt , note$
i = i + 1
wend
end sub
Re: creating wav's ?
Post by Richard Russell on Dec 16th, 2016, 2:46pm
on Dec 15th, 2016, 1:59pm, Richard Russell wrote:You can extend that technique to create the entire WAV header struct correctly. |
|
Rod has written elsewhere that "You don't need a struct to create the header for a .wav file". Of course you don't need one, but using a struct is preferable to any other method. After all that's how the original C code was written, and it makes the program much clearer and easier to understand, as well as reducing the likelihood of a mistake being made.
As an illustration of the benefits of using a struct you just need to compare this code:
Code: wavh.BlockAlign.struct=wavh.Channels.struct*wavh.BitsPerSample.struct/8
with this:
Code: blockAlign=(bitsPerSample*channels)/8
number=blockAlign
byte2=int(number/256)
byte1=number-(byte2*256)
header$=header$+chr$(byte1)+chr$(byte2) ' block align
Don't return to the stone age! Use structs to the full; you know it makes sense!
Richard.
Re: creating wav's ?
Post by Richard Russell on Dec 16th, 2016, 2:55pm
on Dec 16th, 2016, 10:48am, bluatigro wrote:how do i do this whit 16 bit muzik ? |
|
Here is the original program modified for 16-bits:
Code: struct wavh,_
rID as ulong, _ ' "RIFF"
rLen as ulong, _ ' file size minus 8
wID as ulong, _ ' "WAVE"
fID as ulong, _ ' "fmt "
fLen as ulong, _ ' 16
FmtTag as word, _ ' 1
Channels as word, _ ' 1 = Mono, 2 = Stereo
SampleRate as ulong, _ ' 11025 = 11kHz, 22050 = 22 kHz, etc.
AvgBytesPerSec as ulong, _ ' SampleRate*Channels*BitsPerSample/8
BlockAlign as word,_ ' Channels * BitsPerSample/8
BitsPerSample as word,_ ' 8, 16, etc.
dID as ulong,_ ' "data"
dLen as ulong ' length in bytes of the sound buffer
wavh.rID.struct = hexdec("46464952") ' "RIFF"
wavh.wID.struct = hexdec("45564157") ' "WAVE"
wavh.fID.struct = hexdec("20746D66") ' "fmt "
wavh.dID.struct = hexdec("61746164") ' "data"
samplerate = 11025
sec = 1
bufsize = samplerate * sec * 2
fr = 440
wavh.rLen.struct = len(wavh.struct) + bufsize - 8
wavh.fLen.struct = 16
wavh.FmtTag.struct = 1
wavh.Channels.struct = 1 ' Mono
wavh.SampleRate.struct = samplerate
wavh.BitsPerSample.struct = 16
wavh.AvgBytesPerSec.struct = wavh.SampleRate.struct * _
wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.BlockAlign.struct = wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.dLen.struct = bufsize
pi = atn( 1 ) * 4
open "440_1000.wav" for output as #1
print #1, wavh.struct;
for i = 1 to bufsize
sample = sin( i * fr * pi * 2 / samplerate ) * 32767
print #1, chr$(sample and 255);chr$((sample and 65280)/256);
next
close #1
playwave "440_1000.wav"
print "Ready"
end
Richard.
Re: creating wav's ?
Post by bluatigro on Dec 17th, 2016, 10:32am
update :
16 bit muzik !!
error :
my melody stops halfway
Code:
struct wavh,_
rID as ulong, _ ' "RIFF"
rLen as ulong, _ ' file size minus 8
wID as ulong, _ ' "WAVE"
fID as ulong, _ ' "fmt "
fLen as ulong, _ ' 16
FmtTag as word, _ ' 1
Channels as word, _ ' 1 = Mono, 2 = Stereo
SampleRate as ulong, _ ' 11025 = 11kHz, 22050 = 22 kHz, etc.
AvgBytesPerSec as ulong, _ ' SampleRate*Channels*BitsPerSample/8
BlockAlign as word,_ ' Channels * BitsPerSample/8
BitsPerSample as word,_ ' 8, 16, etc.
dID as ulong,_ ' "data"
dLen as ulong ' length in bytes of the sound buffer
wavh.rID.struct = hexdec("46464952") ' "RIFF"
wavh.wID.struct = hexdec("45564157") ' "WAVE"
wavh.fID.struct = hexdec("20746D66") ' "fmt "
wavh.dID.struct = hexdec("61746164") ' "data"
global samplerate
samplerate = 11025
sec = 16
global bufsize
bufsize = samplerate * sec
global pi , tel
pi = atn( 1 ) * 4
dim fr( bufsize )
call addnote 3 , "e" , 1/2
call addnote 3 , "g" , 1/2
call addnote 3 , "c" , 1/2
call addnote 3 , "e" , 1/2
call addnote 3 , "e" , 1/4
call addnote 3 , "d" , 1/4
call addnote 3 , "f" , 1/2
call addnote 3 , "f" , 1
call addnote 3 , "d" , 1/2
call addnote 3 , "f" , 1/4
call addnote 3 , "f" , 1/4
call addnote 3 , "b" , 1/2
call addnote 3 , "d" , 1/2
call addnote 3 , "d" , 1/4
call addnote 3 , "c" , 1/4
call addnote 3 , "e" , 1/2
call addnote 3 , "e" , 1
call addnote 3 , "e" , 1/4
call addnote 3 , "e" , 1/4
call addnote 3 , "g" , 1/4
call addnote 3 , "g" , 1/4
call addnote 3 , "c" , 1/2
call addnote 3 , "e" , 1/4
call addnote 3 , "e" , 1/4
call addnote 3 , "e" , 1/4
call addnote 3 , "d" , 1/4
call addnote 3 , "f" , 1/2
call addnote 3 , "f" , 1
call addnote 3 , "d" , 1/2
call addnote 3 , "f" , 1/4
call addnote 3 , "f" , 1/4
call addnote 3 , "b" , 1/2
call addnote 3 , "d" , 1/2
call addnote 3 , "d" , 1/4
call addnote 3 , "c" , 1/4
call addnote 3 , "c" , 1/2
call addnote 3 , "c" , 1
call savewav "wav\marianne"
print "Ready"
playwave "wav\marianne.wav" , async
print "playing wav"
end
function hz( okt , note )
hz = 55 * 2 ^ ( okt + note / 16 )
end function
sub addnote okt , note$ , l
note = ( instr( "a a#b b#c c#d d#e e#f f#g g#" , note$ ) - 1 ) / 2
if tel >= bufsize then exit sub
for i = tel to tel + int( l * samplerate )
if note < 0 then
fr(i) = 0
else
fr(i) = hz( okt , note )
end if
next i
tel = tel + int( l * samplerate )
end sub
sub savewav file$
wavh.rLen.struct = len(wavh.struct) + bufsize - 8
wavh.fLen.struct = 16
wavh.FmtTag.struct = 1
wavh.Channels.struct = 1 ' Mono
wavh.SampleRate.struct = samplerate
wavh.BitsPerSample.struct = 16
wavh.AvgBytesPerSec.struct = wavh.SampleRate.struct * _
wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.BlockAlign.struct = wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.dLen.struct = bufsize
open file$ + ".wav" for output as #wav
print #wav , wavh.struct;
for i = 1 to bufsize
sample = sin( i * fr(i) * pi * 2 / samplerate ) * 32767
low = sample and 255
high = ( sample and 65280 ) / 256
print #wav , chr$( low ) ; chr$( high ) ;
next i
close #wav
end sub
Re: creating wav's ?
Post by Richard Russell on Dec 17th, 2016, 1:32pm
on Dec 17th, 2016, 10:32am, bluatigro wrote:
Your calculation of bufsize is off by a factor-of-two:
Code:global bufsize
bufsize = samplerate * sec
This is the number of samples, not the number of bytes! It's easy to do the calculation properly because you already know the 'average bytes per second' value from the structure. So here is the corrected sum:
Code: bufsize = wavh.AvgBytesPerSec.struct * sec
Needless to say you must be very careful where in the program you perform this calculation (after the variables referenced in the right-hand-side are set, but before the bufsize variable is used)! LB's behavior of assuming an undefined variable has the value zero, rather than reporting an error, is extremely unhelpful in this regard.
Edit: There are 12 semitones in an octave, not 16 !!!!
Richard.
Re: creating wav's ?
Post by bluatigro on Dec 19th, 2016, 09:02am
richard wrote Quote:Edit: There are 12 semitones in an octave, not 16 !!!! |
|
i dont know whitch of the #'s dont exist
i m not a muzik pro
Re: creating wav's ?
Post by bluatigro on Dec 19th, 2016, 09:52am
update :
key's for up|down
has a error
Code:
struct wavh,_
rID as ulong, _ ' "RIFF"
rLen as ulong, _ ' file size minus 8
wID as ulong, _ ' "WAVE"
fID as ulong, _ ' "fmt "
fLen as ulong, _ ' 16
FmtTag as word, _ ' 1
Channels as word, _ ' 1 = Mono, 2 = Stereo
SampleRate as ulong, _ ' 11025 = 11kHz, 22050 = 22 kHz, etc.
AvgBytesPerSec as ulong, _ ' SampleRate*Channels*BitsPerSample/8
BlockAlign as word,_ ' Channels * BitsPerSample/8
BitsPerSample as word,_ ' 8, 16, etc.
dID as ulong,_ ' "data"
dLen as ulong ' length in bytes of the sound buffer
wavh.rID.struct = hexdec("46464952") ' "RIFF"
wavh.wID.struct = hexdec("45564157") ' "WAVE"
wavh.fID.struct = hexdec("20746D66") ' "fmt "
wavh.dID.struct = hexdec("61746164") ' "data"
wavh.fLen.struct = 16
wavh.FmtTag.struct = 1
wavh.Channels.struct = 2 ' stereo
wavh.SampleRate.struct = samplerate
wavh.BitsPerSample.struct = 16
wavh.AvgBytesPerSec.struct = wavh.SampleRate.struct * _
wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.BlockAlign.struct = wavh.Channels.struct * wavh.BitsPerSample.struct/8
global samplerate , sec
samplerate = 11025
sec = 5
global bufsize
bufsize = wavh.AvgBytesPerSec.struct * sec
global pi , tel
pi = atn( 1 ) * 4
dim fr( bufsize ) , fl( bufsize )
dim l$( sec * 8 ) , r$( sec * 8 )
global wavfile$ , txtfile$
menu #m , "file" _
, "new" , [new] _
, "load txt" , [loadTxt] _
, "save txt" , [saveTxt] _
, "save wav" , [saveWav] _
, "play wav" , [play] _
, "exit" , [quit]
WindowWidth = 1024
WindowHeight = 768
global winx , winy
winx = WindowWidth
winy = WindowHeight
global chanel , red , green , screeny
red = 0
green = 1
menu #m , "chanel" _
, "red" , [red] _
, "green" , [green]
nomainwin
open "muzik creator 0.2" for graphics as #m
#m "trapclose [quit]"
#m "when leftButtonDown [leftDown]"
#m "when rightButtonDown [rightDown]"
#m "when characterInput [key]"
#m "setfocus"
call drawmuzik
timer 100 , [timer]
wait
[timer]
scan
wait
[quit]
close #m
end
[new]
for i = 0 to 40
l$(i) = "-0"
r$(i) = "-0"
next i
screeny = 0
screenx = 0
call drawmuzik
wait
[loadTxt]
'' filedialog "load txt" , ".txt" ; txtfile$
'' open txtfile$ for input as #txtin
'' ''todo read l$() + r$() from file
'' close #txtin
wait
[saveTxt]
'' filedialog "save txt" , ".txt" ; txtfile$
'' open txtfile$ for output as #txtout
'' ''todo write l$() and r$() to file
'' close #txtout
wait
[leftDown]
x = int( MouseX / 30 )
y = int( MouseY / 30 ) - 2
x = int( x / 2 ) * 2
if y < 0 then wait
n$ = mid$( "a a#b b#c c#d d#e e#f f#g g#" , x+1 , 2 )
if chanel = red then
l$( y ) = n$ ; 3
else
r$( y ) = n$ ; 3
end if
call drawmuzik
wait
[rightDown]
x = int( MouseX / 30 ) - 2 + screenx
y = int( MouseY / 30 ) - 2 + screeny
if y < 0 then wait
if chanel = red then
l$( y ) = "-0"
else
r$( y ) = "-0"
end if
call drawmuzik
wait
[saveWav]
for i = 0 to 40
wl$ = l$( i )
wr$ = r$( i )
lo = val( right$( wl$ , 1 ) )
ln$ = left$( wl$ , len( wl$ ) - 1 )
ro = val( right$( wr$ , 1 ) )
rn$ = left$( wr$ , len( wr$ ) - 1 )
call add lo , ln$ , ro , rn$
next i
filedialog "save wav" , "*.wav" , wavfile$
call savewav wavfile$
wait
[play]
playwave wavfile$
wait
[red]
chanel = red
wait
[green]
chanel = green
wait
[key]
select case right$( InkeyS , 1 )
case chr$( _VK_UP )
if screeny > 0 then
screenyb = sreeny - 1
end if
case chr$( _VK_DOWN )
if screeny < sec * 8 - 14 then
screeny = screeny + 1
end if
case chr$( _VK_LEFT )
case chr$( _VK_RIGHT )
case else
end select
call drawmuzik
wait
sub drawmuzik
#m "fill black"
#m "font 20 bold"
#m "backcolor blue"
q$ = "a a#b b#c c#d d#e e#f f#g g#"
for i = 1 to len( q$ ) step 2
call drawnote int(i/2) , -1 , mid$( q$ , i , 2 ) , "blue"
next i
#m "color blue"
for i = 0 to 14
#m "down"
#m "line ";i*30+60;" 0 ";i*30+60;" ";14*30+60
#m "up"
next i
for i = 0 to 14
#m "down"
#m "line 0 ";i*30+60;" ";14*30+60;" ";i*30+60
#m "up"
next i
#m "color black"
#m "font 20 bold"
for i = screeny to screeny + 14
l$ = left$( l$(i) , len( l$(i) ) - 1 )
r$ = left$( r$(i) , len( l$(i) ) - 1 )
ln = ( instr( q$ , l$ ) - 1 ) / 2
rn = ( instr( q$ , r$ ) - 1 ) / 2
#m "goto 0 " ; i * 30 + 60 - screeny * 30
#m "down"
#m "backcolor blue"
#m "\" ; nr$( i , 2 )
#m "up"
if ln = rn then
call drawnote ln , i-screeny , l$ , "yellow"
else
call drawnote ln , i-screeny , l$ , "red"
call drawnote rn , i-screeny , r$ , "green"
end if
next i
end sub
function nr$( no , m )
nr$ = right$( "00000000" ; no , m )
end function
sub drawnote x , y , n$ , kl$
if x < 0 then exit sub
#m "goto ";x*30+60;" ";y*30+60
#m "backcolor ";kl$
#m "down"
#m "\";n$
#m "up"
end sub
function hz( okt , note )
hz = 55 * 2 ^ ( okt + note / 16 )
end function
sub add lokt , lnote$ , rokt , rnote$
lnote = ( instr( "a a#b b#c c#d d#e e#f f#g g#" , lnote$ ) - 1 ) / 2
rnote = ( instr( "a a#b b#c c#d d#e e#f f#g g#" , rnote$ ) - 1 ) / 2
if tel >= bufsize then exit sub
for i = tel to tel + int( 1/8 * samplerate )
if lnote < 0 then
fl(i) = 0
else
fl(i) = hz( lokt , lnote )
end if
if rnote < 0 then
fr(i) = 0
else
fr(i) = hz( rokt , rnote )
end if
next i
tel = tel + int( 1/8 * samplerate )
end sub
sub savewav file$
wavh.rLen.struct = len(wavh.struct) + bufsize - 8
wavh.dLen.struct = bufsize
open file$ for output as #wav
print #wav , wavh.struct;
for i = 1 to bufsize
sample = sin( i * fl(i) * pi * 2 / samplerate ) * 32767
low = sample and 255
high = ( sample and 65280 ) / 256
print #wav , chr$( low ) ; chr$( high ) ;
sample = sin( i * fr(i) * pi * 2 / samplerate ) * 32767
low = sample and 255
high = ( sample and 65280 ) / 256
print #wav , chr$( low ) ; chr$( high ) ;
next i
close #wav
end sub
Re: creating wav's ?
Post by Richard Russell on Dec 19th, 2016, 10:40am
on Dec 19th, 2016, 09:02am, bluatigro wrote:i dont know whitch of the #'s dont exist i m not a muzik pro |
|
You can look at a piano keyboard (I know you have vision problems but I assume you are able to see the white and black keys OK). The 12 semitones (starting from A) are:
Code:A
A# or B flat
B
C
C# or D flat
D
D# or E flat
E
F
F# or G flat
G
G# or A flat
That's 7 white notes and 5 black notes in the octave.
I like to point out to my musical friends that the value 8 doesn't come into it at all, so why is it called an octave? It should be called a septave!
Richard.
Re: creating wav's ?
Post by bluatigro on Dec 22nd, 2016, 08:45am
update :
wav muzik maker 12 0.3
error :
mouse not red good
key not red good
Code:
struct wavh,_
rID as ulong, _ ' "RIFF"
rLen as ulong, _ ' file size minus 8
wID as ulong, _ ' "WAVE"
fID as ulong, _ ' "fmt "
fLen as ulong, _ ' 16
FmtTag as word, _ ' 1
Channels as word, _ ' 1 = Mono, 2 = Stereo
SampleRate as ulong, _ ' 11025 = 11kHz, 22050 = 22 kHz, etc.
AvgBytesPerSec as ulong, _ ' SampleRate*Channels*BitsPerSample/8
BlockAlign as word,_ ' Channels * BitsPerSample/8
BitsPerSample as word,_ ' 8, 16, etc.
dID as ulong,_ ' "data"
dLen as ulong ' length in bytes of the sound buffer
wavh.rID.struct = hexdec("46464952") ' "RIFF"
wavh.wID.struct = hexdec("45564157") ' "WAVE"
wavh.fID.struct = hexdec("20746D66") ' "fmt "
wavh.dID.struct = hexdec("61746164") ' "data"
global samplerate , sec , notestr$
samplerate = 11025
sec = 5
notestr$ = "a a# b c c# d d#e e#f g g#"
wavh.fLen.struct = 16
wavh.FmtTag.struct = 1
wavh.Channels.struct = 2 ' stereo
wavh.SampleRate.struct = samplerate
wavh.BitsPerSample.struct = 16
wavh.AvgBytesPerSec.struct = wavh.SampleRate.struct * _
wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.BlockAlign.struct = wavh.Channels.struct * wavh.BitsPerSample.struct/8
global bufsize
bufsize = wavh.AvgBytesPerSec.struct * sec
global pi , tel
pi = atn( 1 ) * 4
dim fr( bufsize ) , fl( bufsize )
dim l$( sec * 8 ) , r$( sec * 8 )
global wavfile$ , txtfile$
menu #m , "file" _
, "new" , [new] _
, "load txt" , [loadTxt] _
, "save txt" , [saveTxt] _
, "save wav" , [saveWav] _
, "play wav" , [play] _
, "exit" , [quit]
WindowWidth = 1024
WindowHeight = 768
global winx , winy
winx = WindowWidth
winy = WindowHeight
global chanel , red , green , screeny , screenx
red = 0
green = 1
menu #m , "chanel" _
, "red" , [red] _
, "green" , [green]
menu #m , "help"_
, "?" , [help] _
, "about" , [info]
nomainwin
open "wav muzik maker 12 0.3" for graphics as #m
#m "trapclose [quit]"
#m "when leftButtonDown [leftDown]"
#m "when rightButtonDown [rightDown]"
#m "when characterInput [key]"
#m "setfocus"
call drawmuzik
timer 100 , [timer]
wait
[timer]
scan
wait
[quit]
close #m
end
[new]
for i = 0 to 40
l$(i) = "-0"
r$(i) = "-0"
next i
screeny = 0
screenx = 0
call drawmuzik
wait
[loadTxt]
'' filedialog "load txt" , ".txt" ; txtfile$
'' open txtfile$ for input as #txtin
'' ''todo read l$() + r$() from file
'' close #txtin
wait
[saveTxt]
'' filedialog "save txt" , ".txt" ; txtfile$
'' open txtfile$ for output as #txtout
'' ''todo write l$() and r$() to file
'' close #txtout
wait
[leftDown]
x = int( MouseX / 30 ) - 2 + screenx
y = int( MouseY / 30 ) - 2 + screeny
x = int( x / 2 ) * 2
if y < 0 then wait
n$ = mid$( notestr$ , x+1 , 2 )
if chanel = red then
l$( y ) = n$ ; 3
else
r$( y ) = n$ ; 3
end if
call drawmuzik
wait
[rightDown]
x = int( MouseX / 30 ) - 2 + screenx
y = int( MouseY / 30 ) - 2 + screeny
if y < 0 then wait
if chanel = red then
l$( y ) = "-0"
else
r$( y ) = "-0"
end if
call drawmuzik
wait
[saveWav]
tel = 0
for i = 0 to 40
wl$ = l$( i )
wr$ = r$( i )
lo = val( right$( wl$ , 1 ) )
ln$ = left$( wl$ , len( wl$ ) - 1 )
ro = val( right$( wr$ , 1 ) )
rn$ = left$( wr$ , len( wr$ ) - 1 )
call add lo , ln$ , ro , rn$
next i
filedialog "save wav" , "*.wav" , wavfile$
call savewav wavfile$
wait
[play]
playwave wavfile$
wait
[red]
chanel = red
wait
[green]
chanel = green
wait
[help]
notice chr$(13) _
+ "Welkome by wav muzik maker 0.2 ." + chr$(13) _
+ "Instructions : " + chr$(13) _
+ "use mouse left to slect a note ." + chr$(13) _
+ "use mouse right to unselect a note ." + chr$(13) _
+ "use cursor key's to move selection of muzik ."
wait
[info]
notice chr$(13) _
+ "Made by bluatigro ." + chr$(13) _
+ "whit help from rod ."
wait
[key]
select case right$( InkeyS , 1 )
case chr$( _VK_UP )
if screeny > 0 then
screenyb = sreeny - 1
end if
case chr$( _VK_DOWN )
if screeny < sec * 8 - 14 then
screeny = screeny + 1
end if
case chr$( _VK_LEFT )
case chr$( _VK_RIGHT )
case else
end select
call drawmuzik
wait
sub drawmuzik
#m "fill black"
#m "font 20 bold"
#m "backcolor cyan"
for i = 1 to len( notestr$ ) step 2
call drawnote int(i/2) , -1 , mid$( notestr$ , i , 2 ) , "cyan"
next i
#m "color cyan"
for i = 0 to 14
#m "down"
#m "line ";i*30+60;" 0 ";i*30+60;" ";14*30+60
#m "up"
next i
for i = 0 to 14
#m "down"
#m "line 0 ";i*30+60;" ";14*30+60;" ";i*30+60
#m "up"
next i
#m "color black"
#m "font 20 bold"
for i = screeny to screeny + 14
l$ = left$( l$(i) , len( l$(i) ) - 1 )
r$ = left$( r$(i) , len( l$(i) ) - 1 )
ln = ( instr( q$ , l$ ) - 1 ) / 2
rn = ( instr( q$ , r$ ) - 1 ) / 2
call drawnote 0 , i - screeny , nr$( i , 2 ) , "cyan"
if ln = rn then
call drawnote ln , i-screeny , l$ , "yellow"
else
call drawnote ln , i-screeny , l$ , "red"
call drawnote rn , i-screeny , r$ , "green"
end if
next i
end sub
function nr$( no , m )
nr$ = right$( "00000000" ; no , m )
end function
sub drawnote x , y , n$ , kl$
if x < 0 then exit sub
#m "goto ";x*30+60;" ";y*30+60
#m "backcolor ";kl$
#m "down"
#m "\";n$
#m "up"
end sub
function hz( okt , note )
hz = 55 * 2 ^ ( okt + note / 12 )
end function
sub add lokt , lnote$ , rokt , rnote$
lnote = ( instr( notestr$ , lnote$ ) - 1 ) / 2
rnote = ( instr( notestr$ , rnote$ ) - 1 ) / 2
if tel >= bufsize then exit sub
for i = tel to tel + int( 1/8 * samplerate )
if lnote < 0 then
fl(i) = 0
else
fl(i) = hz( lokt , lnote )
end if
if rnote < 0 then
fr(i) = 0
else
fr(i) = hz( rokt , rnote )
end if
next i
tel = tel + int( 1/8 * samplerate )
end sub
sub savewav file$
wavh.rLen.struct = len(wavh.struct) + bufsize - 8
wavh.dLen.struct = bufsize
open file$ for output as #wav
print #wav , wavh.struct;
for i = 1 to bufsize
sample = sin( i * fl(i) * pi * 2 / samplerate ) * 32767
low = sample and 255
high = ( sample and 65280 ) / 256
print #wav , chr$( low ) ; chr$( high ) ;
sample = sin( i * fr(i) * pi * 2 / samplerate ) * 32767
low = sample and 255
high = ( sample and 65280 ) / 256
print #wav , chr$( low ) ; chr$( high ) ;
next i
close #wav
end sub
Re: creating wav's ?
Post by bluatigro on Dec 22nd, 2016, 09:54am
update :
mouse and key's fixed
wav stereo muzik maker 1.0 ready
todo :
[loadTxt]
[saveTxt]
scroling left|right
Code:
struct wavh,_
rID as ulong, _ ' "RIFF"
rLen as ulong, _ ' file size minus 8
wID as ulong, _ ' "WAVE"
fID as ulong, _ ' "fmt "
fLen as ulong, _ ' 16
FmtTag as word, _ ' 1
Channels as word, _ ' 1 = Mono, 2 = Stereo
SampleRate as ulong, _ ' 11025 = 11kHz, 22050 = 22 kHz, etc.
AvgBytesPerSec as ulong, _ ' SampleRate*Channels*BitsPerSample/8
BlockAlign as word,_ ' Channels * BitsPerSample/8
BitsPerSample as word,_ ' 8, 16, etc.
dID as ulong,_ ' "data"
dLen as ulong ' length in bytes of the sound buffer
wavh.rID.struct = hexdec("46464952") ' "RIFF"
wavh.wID.struct = hexdec("45564157") ' "WAVE"
wavh.fID.struct = hexdec("20746D66") ' "fmt "
wavh.dID.struct = hexdec("61746164") ' "data"
global samplerate , sec , notestr$
samplerate = 11025
sec = 5
notestr$ = "a a#b c c#d d#e e#f g g#"
wavh.fLen.struct = 16
wavh.FmtTag.struct = 1
wavh.Channels.struct = 2 ' stereo
wavh.SampleRate.struct = samplerate
wavh.BitsPerSample.struct = 16
wavh.AvgBytesPerSec.struct = wavh.SampleRate.struct * _
wavh.Channels.struct * wavh.BitsPerSample.struct/8
wavh.BlockAlign.struct = wavh.Channels.struct * wavh.BitsPerSample.struct/8
global bufsize
bufsize = wavh.AvgBytesPerSec.struct * sec
global pi , tel
pi = atn( 1 ) * 4
dim fr( bufsize ) , fl( bufsize )
dim l$( sec * 8 ) , r$( sec * 8 )
global wavfile$ , txtfile$
menu #m , "file" _
, "new" , [new] _
, "load txt" , [loadTxt] _
, "save txt" , [saveTxt] _
, "save wav" , [saveWav] _
, "play wav" , [play] _
, "exit" , [quit]
WindowWidth = 1024
WindowHeight = 768
global winx , winy
winx = WindowWidth
winy = WindowHeight
global chanel , red , green , screeny , screenx
red = 0
green = 1
menu #m , "chanel" _
, "red" , [red] _
, "green" , [green]
menu #m , "help"_
, "?" , [help] _
, "about" , [info]
nomainwin
open "wav stereo muzik maker 1.0" for graphics as #m
#m "trapclose [quit]"
#m "when leftButtonDown [leftDown]"
#m "when rightButtonDown [rightDown]"
#m "when characterInput [key]"
#m "setfocus"
call drawmuzik
timer 100 , [timer]
wait
[timer]
scan
wait
[quit]
close #m
end
[new]
for i = 0 to 40
l$(i) = "-0"
r$(i) = "-0"
next i
screeny = 0
screenx = 0
call drawmuzik
wait
[loadTxt]
'' filedialog "load txt" , ".txt" ; txtfile$
'' open txtfile$ for input as #txtin
'' ''todo read l$() + r$() from file
'' close #txtin
wait
[saveTxt]
'' filedialog "save txt" , ".txt" ; txtfile$
'' open txtfile$ for output as #txtout
'' ''todo write l$() and r$() to file
'' close #txtout
wait
[leftDown]
x = int( MouseX / 30 ) - 2 + screenx
y = int( MouseY / 30 ) - 2 + screeny
if y < 0 then wait
n$ = mid$( notestr$ , x*2+1 , 2 )
if chanel = red then
l$( y ) = n$ ; 3
else
r$( y ) = n$ ; 3
end if
call drawmuzik
wait
[rightDown]
x = int( MouseX / 30 ) - 2 + screenx
y = int( MouseY / 30 ) - 2 + screeny
if y < 0 then wait
if chanel = red then
l$( y ) = "-0"
else
r$( y ) = "-0"
end if
call drawmuzik
wait
[saveWav]
tel = 0
for i = 0 to 40
wl$ = l$( i )
wr$ = r$( i )
lo = val( right$( wl$ , 1 ) )
ln$ = left$( wl$ , len( wl$ ) - 1 )
ro = val( right$( wr$ , 1 ) )
rn$ = left$( wr$ , len( wr$ ) - 1 )
call add lo , ln$ , ro , rn$
next i
filedialog "save wav" , "*.wav" , wavfile$
call savewav wavfile$
wait
[play]
filedialog "play wav" , "*.wav" , wavfile$
playwave wavfile$
wait
[red]
chanel = red
wait
[green]
chanel = green
wait
[help]
notice chr$(13) _
+ "Welkome by wav muzik maker 0.2 ." + chr$(13) _
+ "Instructions : " + chr$(13) _
+ "use mouse left to slect a note ." + chr$(13) _
+ "use mouse right to unselect a note ." + chr$(13) _
+ "use cursor key's to move selection of muzik ."
wait
[info]
notice chr$(13) _
+ "Made by bluatigro ." + chr$(13) _
+ "whit help from rod ."
wait
[key]
select case right$( Inkey$ , 1 )
case chr$( _VK_UP )
if screeny > 0 then
screeny = screeny - 1
end if
case chr$( _VK_DOWN )
if screeny < sec * 8 - 14 then
screeny = screeny + 1
end if
case chr$( _VK_LEFT )
case chr$( _VK_RIGHT )
case else
end select
call drawmuzik
wait
sub drawmuzik
#m "fill black"
#m "font 20 bold"
for i = 1 to 24 step 2
call drawnote int(i/2) , -1 _
, mid$( notestr$ , i , 2 ) _
, "blue" , "white"
next i
#m "color blue"
for i = 0 to 14
#m "down"
#m "line ";i*30+60;" 0 ";i*30+60;" ";14*30+60
#m "up"
next i
for i = 0 to 14
#m "down"
#m "line 0 ";i*30+60;" ";14*30+60;" ";i*30+60
#m "up"
next i
for i = screeny to screeny + 14
l$ = left$( l$(i) , len( l$(i) ) - 1 )
r$ = left$( r$(i) , len( r$(i) ) - 1 )
ln = ( instr( notestr$ , l$ ) - 1 ) / 2
rn = ( instr( notestr$ , r$ ) - 1 ) / 2
call drawnote -2 , i - screeny _
, nr$( i , 2 ) , "blue" , "white"
if ln = rn then
call drawnote ln , i-screeny _
, l$ , "yellow" , "black"
else
call drawnote ln , i-screeny _
, l$ , "red" , "white"
call drawnote rn , i-screeny _
, r$ , "green" , "white"
end if
next i
end sub
function nr$( no , m )
nr$ = right$( "00000000" ; no , m )
end function
sub drawnote x , y , n$ , kl$ , kl2$
#m "goto ";x*30+60;" ";y*30+60
#m "color ";kl2$
#m "backcolor ";kl$
#m "down"
#m "\";n$
#m "up"
end sub
function hz( okt , note )
hz = 55 * 2 ^ ( okt + note / 12 )
end function
sub add lokt , lnote$ , rokt , rnote$
lnote = ( instr( notestr$ , lnote$ ) - 1 ) / 2
rnote = ( instr( notestr$ , rnote$ ) - 1 ) / 2
if tel >= bufsize then exit sub
for i = tel to tel + int( 1/8 * samplerate )
if lnote < 0 then
fl(i) = 0
else
fl(i) = hz( lokt , lnote )
end if
if rnote < 0 then
fr(i) = 0
else
fr(i) = hz( rokt , rnote )
end if
next i
tel = tel + int( 1/8 * samplerate )
end sub
sub savewav file$
wavh.rLen.struct = len(wavh.struct) + bufsize - 8
wavh.dLen.struct = bufsize
open file$ for output as #wav
print #wav , wavh.struct;
for i = 1 to bufsize
sample = sin( i * fl(i) * pi * 2 / samplerate ) * 32767
low = sample and 255
high = ( sample and 65280 ) / 256
print #wav , chr$( low ) ; chr$( high ) ;
sample = sin( i * fr(i) * pi * 2 / samplerate ) * 32767
low = sample and 255
high = ( sample and 65280 ) / 256
print #wav , chr$( low ) ; chr$( high ) ;
next i
close #wav
end sub
Re: creating wav's ?
Post by joker on Dec 26th, 2016, 4:59pm
I'm almost sure that you have "tongue firmly in cheek", but since I am not even a music minor I risked asking this question to one over the holidays. Summarizing the answer produces this.
Quote:There are eight notes in a normal scale. Eight scale notes are one octave apart. There wasn't a piano when they started writing music, so the number of keys is irrelevant. |
|
So, if you were kidding, does this sound right or was I bamboozled by a youngster ... again? :D
PS. This is why you, Richard, are important. Your place is to de-bamboozle BASIC for the rest of us.
on Dec 19th, 2016, 10:40am, Richard Russell wrote:You can look at a piano keyboard (I know you have vision problems but I assume you are able to see the white and black keys OK). The 12 semitones (starting from A) are:
Code:A
A# or B flat
B
C
C# or D flat
D
D# or E flat
E
F
F# or G flat
G
G# or A flat That's 7 white notes and 5 black notes in the octave.
I like to point out to my musical friends that the value 8 doesn't come into it at all, so why is it called an octave? It should be called a septave!
Richard.
|
|
Re: creating wav's ?
Post by Richard Russell on Dec 26th, 2016, 9:55pm
on Dec 26th, 2016, 4:59pm, pnlawrence wrote:Summarizing the answer produces this: "There are eight notes in a normal scale. Eight scale notes are one octave apart". |
|
There are seven (not eight) 'notes' in an octave: A, B C, D, E, F and G. If anybody claims there are eight, ask them how many notes there are in two octaves! Or three octaves. That tends to make them think.
The correct answer is of course that there are 7 notes in an octave, 14 in two octaves and 21 in three octaves. Count them yourself.
Another question you can try asking is: if there are 8 notes in an octave, how many semitones are there? To be consistent they would have to answer 13 (the correct answer is of course 12).
I would personally argue that a 'good' musician also needs to be something of a mathematician. They should understand that the equally-tempered scale is logarithmic, that is the ratio between the frequencies of any two consecutive semitones is the same (it has the value 21/12), hence 12 of those steps constitutes an octave.
The value 8 doesn't come into it anywhere.
Richard.
Re: creating wav's ?
Post by joker on Dec 27th, 2016, 02:18am
Quote:There are seven (not eight) 'notes' in an octave: A, B C, D, E, F and G. If anybody claims there are eight, ask them how many notes there are in two octaves! Or three octaves. That tends to make them think. cheesy |
|
Here is what I found by searching for awhile.
http://www.ars-nova.com/Theory%20Q&A/Q104.html
Quote:In that complex sound that makes up a single musical tone there will actually be found a number of pitches combined. There will be a tone that corresponds to the main shape, one that is twice as fast, which is an octave higher, one that is three times as fast, which is a "fifth" above that, and so on. |
|
Quote:There's a more technical discussion of this in the appendix of Exploring Theory, but basically it means that the ear will hear a noticeable agreement between tones that are an octave apart, or a fifth apart, and to a lesser degree to notes that are a fourth or a major third apart, etc. Those are natural stopping places when finding new notes above a starting note, whether you're using a vibrating string or air in a pipe. |
|
Quote:The tradition from which western music derives began with filling in the most obvious stopping places in one octave. And if you go by that process it's easy to end up with seven, but no more. The next pitch is called the octave because it's the eighth note (just as an octopus has eight legs). More than a thousand years ago the letters of the Roman alphabet were adopted to refer to these, and since there were only seven the letters ran A, B, C, D, E, F, G. That gets to the octave, where we hear what sounds like the same thing again, so it makes sense to repeat (though some early writers did use more letters instead of repeating). |
|
Quote:That's why the piano has white keys that form a scale: the first keyboards had only those white keys. More keys (the black keys) were later added to fill in half steps where possible, so that the same melody could be played starting on different notes. |
|
So, the answer seems to be that the term "octave" doesn't refer to the keys or "notes" at all. It refers to the (what I call) harmonics. The "notes" were filled in by musical scholars over the ensuing years.
Re: creating wav's ?
Post by Richard Russell on Dec 27th, 2016, 09:29am
on Dec 27th, 2016, 02:18am, pnlawrence wrote:So, the answer seems to be that the term "octave" doesn't refer to the keys or "notes" at all. It refers to the (what I call) harmonics. |
|
I think there's a danger of over-analysing this. There's surely no confusion or misunderstanding about what an 'octave' is: it's a halving or doubling of frequency (or pitch). Using the term "harmonic" (which can mean any integer multiple) risks, I would say, obfuscating rather than clarifying.
Indeed, the problem with quoting 'musical' references is that they are not written by mathematicians or scientists - so they use imprecise or traditional terminology - and it's mathematics that we are discussing here every bit as much as music!
This thread has not been about what an octave is but rather why it's called an "octave" (a word which derives from the number eight) and how many 'notes' it constitutes. What is entirely clear is that there aren't eight of anything in an octave! There are 12 semitones, and there are 7 'notes' (CDEFGAB or, if you prefer the Tonic Sol-Fa notation, Do Re Mi Fa So La Ti).
Another fun question to ask of an 'octavist' is: 'How many years are there in a decade'? If the same weird logic that leads to the belief there are 8 notes in an octave is applied, one has to accept that there are 11 years in a decade! Both can be represented on a 'number line':
Code:C D E F G A B C D E F G A B C D E F G A B C D...
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2...
Just do the arithmetic. The first line uses seven different symbols and has a periodicity of 7; the second line uses ten different symbols and has a periodicity of 10.
This is not (or should not be) controversial. I am not a musician, but I do understand the mathematics of music and - unlike people who believe there are 8 notes in an octave - I can count!
Richard.
Re: creating wav's ?
Post by joker on Dec 27th, 2016, 10:09am
Quote:... so why is it called an octave? ... |
|
You asked this question, and the answer has little to do with mathematics as I found over and over.
There's no doubt that musicians can count, too. I've seen them tap their feet.
Quote:... it's mathematics that we are discussing here every bit as much as music! ... |
|
Music wasn't created by mathematicians ... those came later trying to explain music, and they generally make terrible music.
Re: creating wav's ?
Post by Richard Russell on Dec 27th, 2016, 11:43am
on Dec 27th, 2016, 10:09am, pnlawrence wrote:Music wasn't created by mathematicians. |
|
True. But now music and mathematics cannot be separated: after all this thread is about sampling theory, the Nyquist criterion and synthesising music from sine waves!
Asking why it's called an octave was perhaps tongue-in-cheek, but it led the OP astray into thinking (quite understandably, if he has no musical background) that there are eight notes rather than seven in an octave. He was similarly misled by the ambiguous term "semitone" into thinking there were 16 of those in an octave!
So whilst we can, I hope, agree on the historical perspective, claiming that there are eight notes in an octave - which many musicians persist in doing even today - is plain wrong and unhelpful.
Richard.
Re: creating wav's ?
Post by joker on Dec 27th, 2016, 2:45pm
Dang! I almost got Richard to say that I found the answer to his question ... almost!
Re: creating wav's ?
Post by Richard Russell on Dec 27th, 2016, 4:18pm
on Dec 27th, 2016, 2:45pm, pnlawrence wrote:Dang! I almost got Richard to say that I found the answer to his question ... almost! |
|
Kudos for being almost as pedantic as I am.
Richard.
Re: creating wav's ?
Post by Jack Kelly on Dec 27th, 2016, 6:25pm
This conversation reminds me of a quote by Leonard Bernstein. He was giving a talk on 'The future of classical music in the 21st century'. In conclusion he said, "I can't remember what the question was, but the answer is 'yes' and it will be chromatic."