Beeper octave range...

A dumb question, I know, but I've found two conflicting sources of information on the octave range of the Sinclair beeper.

I suppose I'm being a little bit lazy, but does anyone know off-hand the octave range of the Speccy beeper.

Andrew
Post edited by andrew_rollings on
«1

Comments

  • edited April 2008
    Defined how? The physical characteristics of the speaker is essentially an undefined answer.
  • edited April 2008
    Defined how?
    You're being too technical. He wants to know the lowest and highest possible notes using the BEEP command.
  • edited April 2008
    In that case, the manual tells you how to find out:
    Type:

    FOR n=0 TO 1000: BEEP .5,n: NEXT n

    This will play notes as high as it can, and then stop with error report B integer out of range. You can print out n to find out how high it did actually get.

    Try the same thing, but going down into the low notes.
  • edited April 2008
    And then divide by 7 to arrive at your octave answer.
  • edited April 2008
    Vertigo wrote: »
    And then divide by 7 to arrive at your octave answer.

    Divide by 12 surely. Go as high as you can go, divide by 12, go as low as you can go, divide by 12 and then add the two answers.

    But this is the spectrum beep command, not the octave range of the beeper. That octave range will be below what squirrels can hear and above what dogs can hear. The driving circuit of the beeper does effectively place a low pass filter with 3db frequency of 11kHz which attenuates frequencies above that and will be dc-coupled which will attenuate low frequencies. I'm sure the mechanical characteristics of the speaker itself has a 3db frequency higher than 11kHz.

    Since the speaker is driven by a 3.5MHz cpu there is much greater output range than '80s sound-generating ics which depended on finite size registers and a fixed clock to generate tone periods, both of which were usually more limited in comparison to what could be mustered by the cpu.

    The highest frequency tone that can be generated by the z80 is probably this:
    loop:
       out (254),a
       xor b
       out (254),a
       xor b
       jp loop
    

    which is 40 cycles and at 3.5MHz corresponds to a tone at 87.5kHz. The lowest frequency that could be generated is effectively 0Hz but let's say 10Hz for purposes of calculating an octave range. Then the octave range would be log(87.5kHz/10Hz)/log 2 = 13 octaves. However the density of high frequency tones that can be generated below 87.5kHz is not too good. If you use the 3db frequency of the driving circuit at 11kHz, which will give good tone generation resolution, but will underestimate the octave range, then you get log(11kHz/10Hz)/log 2 = 10 octaves.
  • edited April 2008
    Well then I suppose it depends if he was asking the simple version of the question or the not so simple version :D

    And I'll have to ask my wife what an octave is ;)
  • edited April 2008
    The highest frequency tone that can be generated by the z80 is probably this:
    loop:
       out (254),a
       xor b
       out (254),a
       xor b
       jp loop
    

    which is 40 cycles and at 3.5MHz corresponds to a tone at 87.5kHz.

    Nice code, what about this:
       ld hl,loop
    loop:
       out (254),a
       xor b
       out (254),a
       xor b
       jp (hl)
    

    34 cycles
  • edited April 2008
    You can obviously get it a bit quicker over many cycles by just unrolling the loop.
  • edited April 2008
    or:
       ld hl,loop
       ld c, 254
    loop:
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       jp (hl)
    

    The problem is, although this might be the highest frequency that you can get the CPU to whack the speaker, these is no musical granularity or quality to this pitch e.g. you couldn't make it play 1,2 or 3 or even 12 "semitones lower" than this frequency.
  • edited April 2008
    There's still a quicker way for some Spectrums ;)
  • edited April 2008
    Dr BEEP wrote: »
    Nice code, what about this:
    Oh see now you've gone and started him off. Yes, well done, very good.
  • edited April 2008
    Vertigo wrote: »
    Oh see now you've gone and started him off. Yes, well done, very good.
    More than that, you've started Woody off...
    I wanna tell you a story 'bout a woman I know...
  • edited April 2008
    Are there tables available anywhere, that show which values need to be sent at which intervals (using OUT 254 rather than calling the ROM beeper routine) to achieve each semitone?
  • edited April 2008
    BloodBaz wrote: »
    or:
       ld hl,loop
       ld c, 254
    loop:
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       out (c),a
       xor b
       jp (hl)
    

    The problem is, although this might be the highest frequency that you can get the CPU to whack the speaker, these is no musical granularity or quality to this pitch e.g. you couldn't make it play 1,2 or 3 or even 12 "semitones lower" than this frequency.

    Risking another comment:

    OUT (C),A appears to be slower than OUT (254),A

    12 Cycles against 11!
    (source www.z80.info)
  • edited April 2008
    bcass wrote: »
    Are there tables available anywhere, that show which values need to be sent at which intervals (using OUT 254 rather than calling the ROM beeper routine) to achieve each semitone?

    A4 is 440 Hz, each octave doubles (or halves, respectively) this, and you have 12 semitones per octave, so it means each semitone multiplies (or divides, respectively) this frequency by twelfth root of two if you want equal temperament. The 48k CPU frequency is 3.5MHz, so it is easy to do the math how many T cycles you need for each semitone. You'll probably want to convert it directly to the timing constants for your OUTing loop, though.

    Of course, these constants give you the values for the entire period. If you want to have some fun with volume, you may change the duty of the wave. This is basically done by adjusting the duration of each half-period, while keeping the total period constant. Keeping the half-periods the same gives you middle duty wave, while extending or shortening the duration of the high level gives you heavier or lower duty wave, respectively. This will work only to some extent though. If you would want to have real volume control, you would need to go for proper synthesis, mixing and 1bit DAC simulation.
  • edited April 2008
    I think this is as fast as it can go (unless you start bringing DMA add-ons into the equation, perhaps...):
      xor a
      ld d,16
      ld bc,254
      ld hl,loop
    loop:
      out (254),a
      out (c),d
      out (254),a
      out (c),d
      out (254),a
      out (c),d
      ; (repeat ad nauseam)
      jp (hl)
    
    23 cycles per period, which works out as 152.173KHz.
  • edited April 2008
    Mine just about doubles the speed of the fastest in this thread so far. Again only on certain Spectrums though ;)

    Edit: No it doesn't double it. That was me being a bit thick there :p
  • edited April 2008
    Patrik Rak wrote: »
    A4 is 440 Hz, each octave doubles (or halves, respectively) this, and you have 12 semitones per octave, so it means each semitone multiplies (or divides, respectively) this frequency by twelfth root of two if you want equal temperament. The 48k CPU frequency is 3.5MHz, so it is easy to do the math how many T cycles you need for each semitone. You'll probably want to convert it directly to the timing constants for your OUTing loop, though.

    Of course, these constants give you the values for the entire period. If you want to have some fun with volume, you may change the duty of the wave. This is basically done by adjusting the duration of each half-period, while keeping the total period constant. Keeping the half-periods the same gives you middle duty wave, while extending or shortening the duration of the high level gives you heavier or lower duty wave, respectively. This will work only to some extent though. If you would want to have real volume control, you would need to go for proper synthesis, mixing and 1bit DAC simulation.

    OT: if im correct you wrote Star Dragon's beeper driver. what it is its tech specs ? (just curious, i like the tune)
  • edited April 2008
    A dumb question, I know, but I've found two conflicting sources of information on the octave range of the Sinclair beeper.

    I suppose I'm being a little bit lazy, but does anyone know off-hand the octave range of the Speccy beeper.

    Andrew

    Eight octaves.

    Probably wrong, but the thread has got way out of hand, so I thought I'd remind you that there are some "normal" people here who can give you straight answers - right or wrong :D:D:D
  • edited April 2008
    Spectrum +2A/+3 only :p
    org     32768
    
                di
                ld      sp,49151
                ld      a,3
                call    FillRam
                ld      a,6
                call    FillRam
                ld      a,7
                call    FillRam
                ld      a,4
                call    FillRam
    
                ld      bc,#7FFD
                ld      a,8
                out     (c),a
                ld      bc,#07FE
                ld      a,#1F
                out     (#FD),a
    
    FillRam:    ld      bc,#7ffd
                or      16
                out     (c),a
    
                pop     ix
                ld      sp,0
                ld      hl,#41ED
                ld      de,#FED3
                ld      bc,16
    FillLoop:   push    hl
                push    de
                djnz    FillLoop
                dec     c
                jr      nz,FillLoop
                jp      (ix)
    
  • edited April 2008
    Eight octaves.

    Probably wrong, but the thread has got way out of hand, so I thought I'd remind you that there are some "normal" people here who can give you straight answers - right or wrong :D:D:D

    I've been very amused by the sudden outbreak of spoddiness :)

    Seriously though, these are all interesting answers, as the two conflicting figures I'd found previously were 5 and 10 octaves...

    This thread will make an interesting footnote in the chapter :D

    Andrew
  • edited April 2008
    Maybe we'll even seen a CGC entry out of all this too. :D
  • edited April 2008
    Oh no Woody!

    You just know the optimisation freaks (you included) are now gunna jump (push hl and return) in...

    "Load 'A' with 8"?

    Are you mad? LOAD the accumulator? You LOAD the ACCUMULATOR?

    With 8?

    ...you are MAD!

    Insane.
  • edited April 2008
    Seriously though, these are all interesting answers, as the two conflicting figures I'd found previously were 5 and 10 octaves...

    For posterity the correct answerTM is 10 octaves. Not sure why anyone would get five except that maybe they ran the BEEP program out of the manual but in one direction only (only +ve semitone values, eg).
    Woody wrote:
    Spectrum +2A/+3 only

    Burn the witch!
  • edited April 2008
    Someone should document all this information in a central location. There seems to be scant data on the net regarding this subject. I was contemplating coding a waveform generator for the beeper a while back, but other than a few old WoS threads, there wasn't much info around, with all my efforts in assembler resulting in 'noise' rather than usable sounds.
  • edited April 2008
    frobush wrote: »
    "Load 'A' with 8"?

    Are you mad? LOAD the accumulator? You LOAD the ACCUMULATOR?

    With 8?

    Ok, being not assembly optimisation minded, what's wrong with that exactly? Anyone care to shed some light on this?
  • edited April 2008
    Well, for starters the section of code here that's referred to is unnecessary in the program. It was a modified +3 test program which I hadn't trimmed down quite enough!
                ld      bc,#7FFD
                ld      a,8
                out     (c),a
    

    But personally I just think fffimS nahtanoJ is a bit of a nutter! :)
  • edited April 2008
    Burn the witch!

    Dons flame-proof jacket.

    And gonad shield :p
  • edited April 2008
    Fikee wrote: »
    OT: if im correct you wrote Star Dragon's beeper driver. what it is its tech specs ? (just curious, i like the tune)

    Not exactly, the player originally comes from Savage, and I don't even remember if I had changed anything at all. It is two channels and drums, and I would have to look up how many octaves it supports, at least six would be my guess, eight being more likely.
  • edited April 2008
    There are some great audio effects in the Savage routine, achieved by interrupts (IM2) IIRC.

    Back to the documentation thing, maybe someone could make a BEEPer wiki? Even if it's just all the info from the various WoS threads on the subject, it would still be a useful reference point. Besides the PC, do any other computers have a beeper?
Sign In or Register to comment.