LB Booster
« creating wav's ? »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:04am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: creating wav's ?  (Read 1668 times)
bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx Re: creating wav's ?
« Reply #8 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
User IP Logged

bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx Re: creating wav's ?
« Reply #9 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
 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: creating wav's ?
« Reply #10 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.

User IP Logged

bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx Re: creating wav's ?
« Reply #11 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
 
User IP Logged

bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx Re: creating wav's ?
« Reply #12 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

 
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: creating wav's ?
« Reply #13 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.

User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: creating wav's ?
« Reply #14 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. cheesy

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.
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: creating wav's ?
« Reply #15 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.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: creating wav's ?
« Reply #16 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.
« Last Edit: Dec 27th, 2016, 10:02am by Richard Russell » User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: creating wav's ?
« Reply #17 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. cheesy

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.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: creating wav's ?
« Reply #18 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.
« Last Edit: Dec 27th, 2016, 11:46am by Richard Russell » User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: creating wav's ?
« Reply #19 on: Dec 27th, 2016, 2:45pm »

Dang! I almost got Richard to say that I found the answer to his question ... almost! cheesy cheesy cheesy
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: creating wav's ?
« Reply #20 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.
User IP Logged

Jack Kelly
Full Member
ImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 106
xx Re: creating wav's ?
« Reply #21 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."
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls