waveform sharing thread
Root / Programming Questions / [.]
randoCreated:
I don't know how WAVESET works.
Tried my best to produce a 440 Hz sine wave and this is what I got:
VAR RATE=14275 VAR W$="" VAR I FOR I=0 TO 512-1 VAR X=I/RATE VAR F=(SIN(2*PI()*440*X)*127)+128 PUSH W$, HEX$(F, 2) NEXT WAVESET 255, 127, 0, 0, 127, W$ BEEP 255 WAIT 60It sort of gives a 440 Hz sine wave? It doesn't sound very nice, though. I have absolutely no clue why the rate is 14275. I just fiddled around with a wave analyser (Audacity) until I found a number that worked (the documentation doesn't mention anything about the sample rate...). This next one plays a 440 Hz and a 1040 Hz sine wave on top of each other... well at least it's supposed to, the frequencies were a bit off again. I tried adjusting the rate again to get them close. I seem to get a 443 Hz wave and a 1036 Hz wave.
VAR RATE=14110 VAR W$="" VAR I FOR I=0 TO 512-1 VAR X=I/RATE VAR F1=(SIN(2*PI()*440*X)*127)+128 VAR F2=(SIN(2*PI()*1040*X)*127)+128 VAR H$=HEX$((F1+F2)/2, 2) PUSH W$, H$ NEXT WAVESET 255, 127, 0, 0, 127, W$ BEEP 255 WAIT 60
You can change the reference note with an optional argument to WAVSET. By default it's 69 which is A in octave 4.
I remember having a lot of problems getting WAVSET to play at the correct speed, particularly with BGMPLAY. I was never able to get it exactly perfect, so it always ended up not playing for the right amount of time, or at the wrong speed/pitch.
HEX$() supports a length parameter, so you can just use HEX$(...,2) rather than adding a 0 if it's too short.
(Also, you appear to be missing a few parentheses in your code)
You can change the reference note with an optional argument to WAVSET. By default it's 69 which is A in octave 4. I remember having a lot of problems getting WAVSET to play at the correct speed, particularly with BGMPLAY. I was never able to get it exactly perfect, so it always ended up not playing for the right amount of time, or at the wrong speed/pitch.How exactly does changing the reference pitch actually alter the waveform? I don't really understand that part.
When you define a waveform like WAVSET 255, 127, 0, 0, 127, W$, 69, it will use that exact waveform (without stretching) for note 69 (A in octave 4) (which is probably the same as BEEP with pitch 0). That in itself means nothing since we don't really know the default sample rate (and how it changes based on the waveform string length), but it does allow you to adjust the pitch more easily:You can change the reference note with an optional argument to WAVSET. By default it's 69 which is A in octave 4. I remember having a lot of problems getting WAVSET to play at the correct speed, particularly with BGMPLAY. I was never able to get it exactly perfect, so it always ended up not playing for the right amount of time, or at the wrong speed/pitch.How exactly does changing the reference pitch actually alter the waveform? I don't really understand that part.
WAVESET 255, 127, 0, 0, 127, W$,69 'normal pitch WAVESET 255, 127, 0, 0, 127, W$,69-12 '1 octave higher WAVESET 255, 127, 0, 0, 127, W$,69+12 '1 octave lower
When you define a waveform like WAVSET 255, 127, 0, 0, 127, W$, 69, it will use that exact waveform (without stretching) for note 69 (A in octave 4) (which is probably the same as BEEP with pitch 0). That in itself means nothing since we don't really know the default sample rate (and how it changes based on the waveform string length), but it does allow you to adjust the pitch more easilyAh okay thanks, that makes sense. It seems the reference pitch is different with WAVESETA though than in WAVESET because if I put it to 69 it does seem to distort the audio and I usually have to set it to 70 somthin.
I don't know how WAVESET works. Tried my best to produce a 440 Hz sine wave and this is what I got:VAR RATE=14275 VAR W$="" VAR I FOR I=0 TO 512-1 VAR X=I/RATE VAR F=(SIN(2*PI()*440*X)*127)+128 PUSH W$, HEX$(F, 2) NEXT WAVESET 255, 127, 0, 0, 127, W$ BEEP 255 WAIT 60It sort of gives a 440 Hz sine wave? It doesn't sound very nice, though. I have absolutely no clue why the rate is 14275. I just fiddled around with a wave analyser (Audacity) until I found a number that worked (the documentation doesn't mention anything about the sample rate...). This next one plays a 440 Hz and a 1040 Hz sine wave on top of each other... well at least it's supposed to, the frequencies were a bit off again. I tried adjusting the rate again to get them close. I seem to get a 443 Hz wave and a 1036 Hz wave.VAR RATE=14110 VAR W$="" VAR I FOR I=0 TO 512-1 VAR X=I/RATE VAR F1=(SIN(2*PI()*440*X)*127)+128 VAR F2=(SIN(2*PI()*1040*X)*127)+128 VAR H$=HEX$((F1+F2)/2, 2) PUSH W$, H$ NEXT WAVESET 255, 127, 0, 0, 127, W$ BEEP 255 WAIT 60
You can change the reference note with an optional argument to WAVSET. By default it's 69 which is A in octave 4. I remember having a lot of problems getting WAVSET to play at the correct speed, particularly with BGMPLAY. I was never able to get it exactly perfect, so it always ended up not playing for the right amount of time, or at the wrong speed/pitch. HEX$() supports a length parameter, so you can just use HEX$(...,2) rather than adding a 0 if it's too short. (Also, you appear to be missing a few parentheses in your code)
You can change the reference note with an optional argument to WAVSET. By default it's 69 which is A in octave 4. I remember having a lot of problems getting WAVSET to play at the correct speed, particularly with BGMPLAY. I was never able to get it exactly perfect, so it always ended up not playing for the right amount of time, or at the wrong speed/pitch.How exactly does changing the reference pitch actually alter the waveform? I don't really understand that part.
When you define a waveform like WAVSET 255, 127, 0, 0, 127, W$, 69, it will use that exact waveform (without stretching) for note 69 (A in octave 4) (which is probably the same as BEEP with pitch 0). That in itself means nothing since we don't really know the default sample rate (and how it changes based on the waveform string length), but it does allow you to adjust the pitch more easily:You can change the reference note with an optional argument to WAVSET. By default it's 69 which is A in octave 4. I remember having a lot of problems getting WAVSET to play at the correct speed, particularly with BGMPLAY. I was never able to get it exactly perfect, so it always ended up not playing for the right amount of time, or at the wrong speed/pitch.How exactly does changing the reference pitch actually alter the waveform? I don't really understand that part.WAVESET 255, 127, 0, 0, 127, W$,69 'normal pitch WAVESET 255, 127, 0, 0, 127, W$,69-12 '1 octave higher WAVESET 255, 127, 0, 0, 127, W$,69+12 '1 octave lower
You all made a spelling error. its wavset. lol cool i like some contributions. but so far ive only got 1 waveform.... This is not meant to be spam! what now?When you define a waveform like WAVSET 255, 127, 0, 0, 127, W$, 69, it will use that exact waveform (without stretching) for note 69 (A in octave 4) (which is probably the same as BEEP with pitch 0). That in itself means nothing since we don't really know the default sample rate (and how it changes based on the waveform string length), but it does allow you to adjust the pitch more easilyAh okay thanks, that makes sense. It seems the reference pitch is different with WAVESETA though than in WAVESET because if I put it to 69 it does seem to distort the audio and I usually have to set it to 70 somthin.