BBC BASIC for Windows
Programming >> Sound, Music and Video >> CD-quality stereo SOUND!
http://bb4w.conforums.com/index.cgi?board=multimedia&action=display&num=1433631006

CD-quality stereo SOUND!
Post by rtr2 on Jun 6th, 2015, 10:50pm

When BB4W was first developed (about 15 years ago) the CPU power then available was only sufficient for the SOUND/ENVELOPE emulation to generate 8-bit mono sound, at a sampling rate of 22,050 Hz. Although the resulting quality is comparable with the BBC Micro's sound output, it is obviously poor by modern standards. Nowadays, there is no such restriction.

Just for fun I have been working on a library which (quite literally) patches the code of BB4W in memory so that it generates 16-bit stereo sound at the standard CD sampling rate of 44,100 Hz. Once patched the SOUND and ENVELOPE statements work normally, except that the channel 0 'noise' facility is unavailable (only 4-voice tone output is supported). A CPU with SSE2 support is required.

I have arbitrarily put channels 0 and 1 on the left and channels 2 and 3 on the right, although the library could be extended to support panning the four SOUND channels to any required L/R mix.

I will release the library in due course, but meanwhile to give you a taster here is Bach's Brandenburg Concerto No.3 from the Yahoo group, after patching (best listened to on headphones):

http://www.rtr.myzen.co.uk/Brandenburg3_4voice_HQ.exe

Richard.
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 8th, 2015, 12:37pm

on Jun 6th, 2015, 10:50pm, g4bau wrote:
here is Bach's Brandenburg Concerto No.3 from the Yahoo group, after patching (best listened to on headphones)

As promised I have replaced the file with a digitally-signed version which should not trigger security warnings:

http://www.rtr.myzen.co.uk/Brandenburg3_4voice_HQ.exe

There is also a video version here, although for some reason it has only mono sound:



Richard.
Re: CD-quality stereo SOUND!
Post by hitsware on Jun 9th, 2015, 9:25pm

Richard,

Since SOUND is restricted to (essentially) squarewaves,
I can't fathom that you are gaining much with increased bandwidth. (Not that it would hurt anything) and 'maybe' I can hear some difference. Do You ? Stereo would be nice.
Maybe some kind of wavefile writer as on the Amiga. Will the FREQOUT function work with your new efforts ?
You certainly are busy for someone at times so jaded smiley
As always thank You for the efforts .........................

Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 9th, 2015, 10:16pm

on Jun 9th, 2015, 9:25pm, hitsware wrote:
Since SOUND is restricted to (essentially) squarewaves

I don't know what makes you think that; it has never been true. Indeed when testing the HQSOUND library I did so initially with sine waves, because that made it easier to assess whether it was working correctly. I added some harmonics in later, to make the tone more interesting, but the waveform can be anything at all (Nyquist allowing).

Quote:
I can't fathom that you are gaining much with increased bandwidth.

Indeed, the increased bandwidth is an incidental advantage. It's the change from 8-bit to 16-bit sampling which, of course, makes the difference quality-wise (reducing the quantising noise from around -30 dB to better than -75 dB).

Quote:
'maybe' I can hear some difference. Do You ?

The difference is amazing, not least the stereo; the output is now indeed 'CD quality' (disregarding things like clicks from unfiltered level transitions). If you can't hear much of an improvement either your ears or your sound card/speakers need mending!

Quote:
Will the FREQOUT function work with your new efforts ?

Yes, the frequency isn't changed at all by the library - even to the extent that the lowest notes still have a pitch error rather larger than would ideally be desirable.

Quote:
You certainly are busy for someone at times so jaded

Busy? You gave me the idea by posting a program using MIDI output and the HQSOUND library was working a few hours later. The entire project took well under a day.

But I have noted the (almost) total lack of interest. In fact this forum is about as dead as BBC BASIC is - which makes sense I guess. sad

Richard.

Re: CD-quality stereo SOUND!
Post by hitsware on Jun 10th, 2015, 12:11am

> I don't know what makes you think that;

Observing with oscilloscope and a knowledge of retro (chip) music production .
Re: CD-quality stereo SOUND!
Post by Richey on Jun 10th, 2015, 05:33am

We'll I represent the B in BASIC - using BBC BASIC for Windows and other BASICs to learn programming, which is a journey and not an event!

While there does seem to be some decline in the use of BASIC, at least on the face of it, for 'serious' applications perhaps as a result of things like Microsoft abandoning QBASIC, the current problems with PowerBASIC following the death of Bob Zale, the abandonment / non-development of open source BASICs by their authors and the non appearance of Liberty BASIC 5 (or v4.5 for that matter) etc, I still think it has a significant presence amongst hobby coders.

I follow the retro computer / coding scene and I'm amazed about how much BASIC coding goes on there by people who are knowledgable in other programming languages; for example, there are people still writing lots of games for the ZXSpectrum and even the 1k ZX81.

I still think that even given the Pythons and Lua's of this world, nothing beats BASIC as an easy to learn and flexible language that provides both a super introduction into coding for ANYONE but (at least in the case of BBC BASIC and some other BASICs) powerful and stable enough to be used to do pretty much ANYTHING!

IMHO a BBC BASIC library for easy GUI would enhance BBC BASIC and improve its potential popularity - this must be worth the time and effort. Would it be difficult to achieve for an experienced and relatively competent coder (that's not me I'm afraid!)?


Re: CD-quality stereo SOUND!
Post by DDRM on Jun 10th, 2015, 07:48am

Hi Richard,

>But I have noted the (almost) total lack of interest. In fact this forum is about as dead as BBC BASIC is - which makes sense I guess.

A little harsh, perhaps! I see the thread has been read 74 times (as I write), and I am certainly looking forward to the release of the library - and it would be nice to have the panning feature - would that be dynamic - so a character could move across the screen, for example?

In the meantime, I am enjoying the Bach very much, even through my speakers. The stereo effects are very impressive!

Best wishes,

D
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 10th, 2015, 08:27am

on Jun 10th, 2015, 12:11am, hitsware wrote:
Observing with oscilloscope and a knowledge of retro (chip) music production.

Observing with an oscilloscope tells you only what waveform I chose to use, not what waveform(s) it could generate. grin

As far as "knowledge of retro chip music production" goes, the fact that the original BBC Micro hardware may have been able to generate only square waves has no bearing on what a software emulation may or may not be able to do. In software, square waves are just about the most difficult thing to generate, because they contain harmonics up to infinity - sine waves are the easiest to generate!

Anyway, for the record, BB4W has always used Direct Digital Synthesis (DDS) for its SOUND output. The waveform is stored in memory (as 16 tables - one for each level setting - with 256 8-bit samples in the case of the built-in functionality and 65536 16-bit samples in the case of HQSOUND). The wave shape can be anything at all, so long as it contains no frequency components which could result in aliasing at the highest output pitch (approx. 2453 Hz, so nothing much higher than an 8th harmonic).

The wave-table generation in the HQSOUND library is simple BASIC code, and could easily be adapted to produce different waveforms. It would even be possible to adapt the library to use a different waveform for each channel and/or each level, although that's something that would need to be left as an exercise for others.

Richard.
Re: CD-quality stereo SOUND!
Post by Edja on Jun 10th, 2015, 08:34am

Quote:
But I have noted the (almost) total lack of interest. In fact this forum is about as dead as BBC BASIC is
This sort of comment, sadly enough, pops up from time to time. It seems most of the forum members are working in silence. To add a positive twist : With more bugs in it (compared to other Basic's/languages) BB4W would certainly fire up more discussion and threads on the forum. Maybe BB4W is just too good a product.
Quote:
a BBC BASIC library for easy GUI would enhance BBC BASIC and improve its potential popularity
So through! I just don't have the skills to contribute to this. Otherwise I would. Really! Of course, I know, this doesn't help.

Eddy

Re: CD-quality stereo SOUND!
Post by hitsware on Jun 10th, 2015, 2:24pm

>
Observing with an oscilloscope tells you only what waveform I chose to use, not what waveform(s) it could generate.
>

I know that.

>
As far as "knowledge of retro chip music production" goes, the fact that the original BBC Micro hardware may have been able to generate only square waves has no bearing on what a software emulation may or may not be able to do. In software, square waves are just about the most difficult thing to generate, because they contain harmonics up to infinity - sine waves are the easiest to generate!

Anyway, for the record, BB4W has always used Direct Digital Synthesis (DDS) for its SOUND output. The waveform is stored in memory (as 16 tables - one for each level setting - with 256 8-bit samples in the case of the built-in functionality and 65536 16-bit samples in the case of HQSOUND). The wave shape can be anything at all, so long as it contains no frequency components which could result in aliasing at the highest output pitch (approx. 2453 Hz, so nothing much higher than an 8th harmonic).
>

You've stated before that your purpose was to emulate the original system ergo the chip. I certainly did not mean to imply that as a limitation.

Re: CD-quality stereo SOUND!
Post by David Williams on Jun 10th, 2015, 3:10pm

on Jun 9th, 2015, 10:16pm, g4bau wrote:
But I have noted the (almost) total lack of interest. In fact this forum is about as dead as BBC BASIC is - which makes sense I guess. sad


I'm risking an "off topic" proclamation here, but a commercial game written entirely in BBC BASIC was published a few months ago. The game's called 'Overlord', and was written by Anthony Bartram for the RISC OS platform (the first original, commercial game for RISC OS in several years). I even bought a copy (at £9.99) - my first purchase of a computer game since perhaps 1993! I enjoyed the game. I think Anthony mentioned in an interview that it sold well at a recent RISC OS show.

(He's probably one of the few that has made any money at all from the RISC OS scene!)

http://www.amcog-games.co.uk/

'Overlord' comes with its source code, and upon inspection it wouldn't be difficult to port it over to BB4W (not that I would do such a thing myself without permission and obviously not without license agreement, even if I had the time).

Heartwarming, isn't it, to know that BBC BASIC is still being used to create commercial products. smiley


David.
--
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 10th, 2015, 5:35pm

on Jun 10th, 2015, 2:24pm, hitsware wrote:
You've stated before that your purpose was to emulate the original system ergo the chip.

Just to remind you, the sound chip on the original BBC Micro was quite primitive, so things like the ENVELOPE functionality were implemented entirely in software rather than in hardware. This contrasts with some other machines of the day which used a more sophisticated chip but provided less functionality.

I look forward to seeing - and hearing - what you (and others) can achieve by modifying the HQSOUND library to support things like dynamic stereo panning, multiple waveforms and the like.

Richard.

Re: CD-quality stereo SOUND!
Post by hitsware on Jun 10th, 2015, 7:24pm

User Image
Re: CD-quality stereo SOUND!
Post by hitsware on Jun 10th, 2015, 7:44pm

" It contains three square wave tone generators and one white noise generator, each of which can produce sounds at various frequencies and sixteen different volume levels."

You may not give those 'primitive' chips their just due.
I strongly surmise that the original ENVELOPE addressed the various registers in the SNhuh
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 10th, 2015, 8:38pm

on Jun 10th, 2015, 7:24pm, hitsware wrote:
User Image

You will get a 'Not in a subroutine' error if you RUN, rather than CALL (or INSTALL) the library. But it's quite normal for a BB4W library to report an error if you RUN it directly - indeed it's inevitable that any module designed to be CALLed will report an error if it is RUN instead - so I wonder what point you are making.

Quote:
I strongly surmise that the original ENVELOPE addressed the various registers in the SN

I think that's unlikely. Although I've never seen the relevant code in the Acorn MOS, I would expect that its structure was similar to my code in BB4W which does the same job. My envelope routine does not directly call any of the code which emulates the 'chip' (i.e. the DDS code) but achieves its effect indirectly by effectively calling the SOUND routine, to set the frequency and amplitude, every centisecond.

Richard.

Re: CD-quality stereo SOUND!
Post by hitsware on Jun 10th, 2015, 9:09pm

> so I wonder what point you are making.

I obviously don't know where to put it .............
It should be filed where to be called ?
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 10th, 2015, 9:42pm

on Jun 10th, 2015, 9:09pm, hitsware wrote:
I obviously don't know where to put it ... It should be filed where to be called ?

When you are running your program from the BB4W IDE it really doesn't matter where you store the library, so long as you specify the appropriate absolute or relative path when you CALL it. In that respect it's like any other 'resource' file used by your program.

But when it comes to compiling your program to an EXE it is obviously much more convenient if you can embed the library file in the executable, which means that it must either be in the LIB folder (which you access using @lib$) or in the same folder as your program (which you access using @dir$), or in a sub-directory of one of those places.

It is conventional to store libraries in the former location (hence the name LIB), although since that's a 'protected' folder in Windows Vista and later you will need to have administrative privileges in order to copy it there. Assuming UAC is enabled, and you copy the file in Windows Explorer (e.g. using copy-and-paste) you will be automatically prompted to grant the necessary privileges.

As is explained in the REMarks within the file itself, you can either use INSTALL (followed by a PROC_hqinit), as you would for a conventional library, or alternatively - because HQSOUND doesn't need to be resident in memory after it has done the patching - you can use CALL instead. The CALL method is particularly useful for those running the trial version of BB4W because it is more memory-efficient.

Because it's the simplest method, when modifying any of my existing four-voice music programs to use the library I simply add this at or near the start:

Code:
      CALL @lib$+"HQSOUND" 

Richard.

Re: CD-quality stereo SOUND!
Post by hitsware on Jun 11th, 2015, 01:14am

Maybe I am becoming deaf ......
No effect for me ... REM CALL or not
Copied file to C/programfiles/bbcbasic/lib
Code:

      CALL @lib$+"HQSOUND"

      *TEMPO 133

      ENVELOPE 1,0,0,0,0,0,0,0,127,0,0,0,40,0
      ENVELOPE 2,0,0,0,0,0,0,0,127,-3,0,0,120,0
      ENVELOPE 3,0,0,0,0,0,0,0,127,-127,0,0,100,0
      ENVELOPE 4,0,0,0,0,0,0,0,0,0,0,0,0,0

      DIM orgn(11), bass(7), drum(7)

      FOR x=0 TO 11: READ orgn(x): NEXT x
      FOR x=0 TO 7: READ bass(x): NEXT x
      FOR x=0 TO 7: READ drum(x): NEXT x

      REPEAT
        FOR x=0 TO 11: FOR y=0 TO 7
            SOUND 0,1,orgn(x)+48,4
            SOUND 1,1,orgn(x)+76,4
            SOUND 2,bass(y),orgn(x),4
            SOUND 3,drum(y),140,4
          NEXT y: NEXT x
      UNTIL FALSE: END

      DATA 32,24,4,32, 4,4,4,4, 24,24,4,4
      DATA 2,4,4,2, 2,4,4,4
      DATA 4,4,3,4, 4,4,3,4


 

Re: CD-quality stereo SOUND!
Post by dfeugey on Jun 11th, 2015, 09:17am

Quote:
It seems most of the forum members are working in silence.

I confirm.

I hope to revive BBC Basic use in France, with some actions not completely related to www.riscos.fr (more a mix of BBC Basic for RISC OS AND Windows).

Quote:
I'm risking an "off topic" proclamation here

And we don't forget your work too smiley

Quote:
Maybe I am becoming deaf ......

Yes, it sounds the same with or without the lib. Strange.
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 11th, 2015, 09:40am

on Jun 11th, 2015, 01:14am, hitsware wrote:
Maybe I am becoming deaf ......

To me the reduction in quantising noise (by more than 40 dB) is dramatic and the stereo effect unmistakable.

In all seriousness if you can't hear any difference (not even that channels 0 & 1 are left-only and channels 2 & 3 right-only) then I would worry about your hearing - or your PC.

Richard.

Re: CD-quality stereo SOUND!
Post by hitsware on Jun 11th, 2015, 2:11pm

Quote:
In all seriousness if you can't hear any difference (not even that channels 0 & 1 are left-only and channels 2 & 3 right-only) then I would worry about your hearing - or your PC.


Playing the code I submitted with my last post ?
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 11th, 2015, 3:52pm

on Jun 11th, 2015, 2:11pm, hitsware wrote:
Playing the code I submitted with my last post ?

I haven't run that code, but something far simpler is adequate to demonstrate the stereo effect:

Code:
      CALL @lib$+"HQSOUND"
      SOUND 1, 0, 0, 10
      SOUND 2, 0, 0, 30
      SOUND 1, -15, 148, 20
      SOUND 2, -15, 168, 20 

That plays a C on the left stereo channel (only) followed by an F on the right channel (only).

But really the stereo aspect is just a (useful) side-effect. The principal objective of the library was to achieve 16-bit rather than 8-bit output, to eliminate the quantising distortion which I've always found unpleasant. Whilst you can guarantee that any modern PC will support 44.1 kHz 16-bit stereo, you can't be so certain that it will support mono with the same parameters.

Richard.

Re: CD-quality stereo SOUND!
Post by hitsware on Jun 11th, 2015, 4:09pm

> I haven't run that code,

Would you please ? .... Then comment on the effects ...

edit:

1) raised speakers off floor and out of corners somewhat
2) turned off EQ
3) completely closed BB4W between comparisons

Now I can hear the L-R 'ness but quieter ?
Tis true my ears are worn, plus I've noticed as my PC's go down in size (and price) the sound quality also declines. Makes sense realizing a SB card uses @ least 12 V, while the MB circuit is probably 3.3V or even 1.8V nowdays ...

Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 11th, 2015, 5:43pm

on Jun 11th, 2015, 4:09pm, hitsware wrote:
Would you please ? .... Then comment on the effects ...

Effects? It plays fine, with what you call 'bass' and 'drum' at 100% right channel and what passes for the 'melody' at 100% left channel. It's also free from the horrible raspy quantising noise that accompanies it when played without HQSOUND (you must restart BB4W for that of course).

Listen to them yourself:

http://www.rtr.myzen.co.uk/standard.wav
http://www.rtr.myzen.co.uk/hqsound.wav

Richard.

Re: CD-quality stereo SOUND!
Post by hitsware on Jun 11th, 2015, 5:54pm

Gotcha ... Thanks .... See edit to last post ....
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 11th, 2015, 5:58pm

on Jun 11th, 2015, 4:09pm, hitsware wrote:
Now I can hear the L-R 'ness but quieter ?

The reduced level is intentional, because with the hugely increased dynamic range there's no need to risk clipping. But that's settable with the 'stereo mix' QWORD in the library so you are free to bump the level up, or play with panning, or whatever.

As I said before the library lacks any 'frills'; tweak it, enhance it, play with it - the code is very amenable to user-modification and that's the way I increasingly want to go as my own interests and abilities wane.

Richard.

Re: CD-quality stereo SOUND!
Post by hitsware on Jun 11th, 2015, 6:22pm

By "quieter ?" I meant I don't know about the noise you refer to ?

Moving along :
Code:
      FOR ALD = -10 TO -1
        CLS
        PRINT "ALD = ";ALD
        FOR duration = 3 TO 10
          ENVELOPE 1,0,0,0,0,0,0,0,127,ALD,0,0,126,0
          SOUND 1,1,4,duration
        NEXT duration
      NEXT ALD
      END
      REM As ALD decreases it does not take the level
      REM all the way down ......
      REM Shouldn't it ?

 

Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 11th, 2015, 7:11pm

on Jun 11th, 2015, 6:22pm, hitsware wrote:
As ALD decreases it does not take the level all the way down ...... Shouldn't it ?

You have:

Code:
          ENVELOPE 1,0,0,0,0,0,0,0,127,ALD,0,0,126,0
          SOUND 1,1,4,duration 

so the final level should be approximately:

Code:
126 + duration * tempo * ALD 


So with duration=10 and ALD=-1 (and assuming the default tempo of 5) the final level should be around 126-50=76 (or 9 on the 0-15 scale). Isn't that what you are finding?

Richard.
Re: CD-quality stereo SOUND!
Post by hitsware on Jun 11th, 2015, 8:25pm

How do I make the envelope go to 0 ?

Adding - numbers to AS does nothing .. ?
Likewise AR
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 11th, 2015, 9:11pm

on Jun 11th, 2015, 8:25pm, hitsware wrote:
How do I make the envelope go to 0 ?

You need to increase the duration to give it time to decay:

Code:
      AD = -1
      duration = 25
      ENVELOPE 1,0,0,0,0,0,0,0,127,AD,0,0,126,0
      SOUND 1,1,100,duration 

But that's too obvious, so did you mean something else?

Quote:
AS does nothing .. ?

It works for me. For example here the note initially decays quickly at the AD rate but 10 centiseconds later switches to decaying at the slower AS rate:

Code:
      AD = -5
      AS = -1
      ALA = 125
      ALD = 75
      duration = 2 + 15
      ENVELOPE 1,0,0,0,0,0,0,0,127,AD,AS,0,ALA,ALD
      SOUND 1,1,100,duration 

Check on an oscilloscope if you want to see it more clearly. You may want to add an initial delay to avoid the sound start-up transient partially masking the effect.

Quote:
Likewise AR

Again it has always worked for me. I thought you were something of an expert on the ADSR envelope so I'm surprised you are having problems with it.

Richard.

Re: CD-quality stereo SOUND!
Post by hitsware on Jun 11th, 2015, 10:21pm

Here I (empiricly) got the envelopes to work to my liking, but at the expense of the channel modifiers (which I never understood and now do even less)
Code:
      ENVELOPE 1,0,0,0,0,0,0,0,127,0,0,-2,127,0
      ENVELOPE 2,0,0,0,0,0,0,0,127,0,0,-4,127,0
      ENVELOPE 3,0,0,0,0,0,0,0,127,0,0,-6,127,0

      DIM note(3,7),selection(16)

      FOR x=1 TO 16: READ selection(x): NEXT x
      DATA 32,40,48,60,68,0,0,0,0,0,0,0,0,0,0,0

      REPEAT
        FOR count=0 TO 7
          FOR voice=0 TO 3
            random1=RND(5)
            random2=RND(16)
            IF random1=1 THEN note(voice,count)=selection(random2)
          NEXT voice
    
          IF SGN(note(1,(count)))=1 THEN
            SOUND 1,1,note(1,(count)),1: SOUND 4097,1,0,4
          ELSE SOUND 4097,1,0,5
          ENDIF
          IF SGN(note(2,(count)))=1 THEN
            SOUND 2,1,note(2,(count)),1: SOUND 4098,1,0,4
          ELSE SOUND 4098,1,0,5
          ENDIF
          IF SGN(note(3,(count)))=1 THEN
            SOUND 3,1,note(3,(count)),1: SOUND 4099,1,0,4
          ELSE SOUND 4099,1,0,5
          ENDIF
    
        NEXT count
      UNTIL FALSE

 

Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 11th, 2015, 10:41pm

on Jun 11th, 2015, 6:22pm, hitsware wrote:
I meant I don't know about the noise you refer to ?

http://en.wikipedia.org/wiki/Quantization_%28signal_processing%29#Quantization_noise_model


Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 11th, 2015, 11:07pm

on Jun 11th, 2015, 10:21pm, hitsware wrote:
the channel modifiers (which I never understood and now do even less)

Well, since the rather vital release phase of the ADSR envelope cannot be used at all without the 'modifiers', can I politely and gently suggest that it would be helpful if you did understand them. smiley

I've checked the descriptions of those bits in the BB4W manual and I can't see how they could be made any clearer. The hold bit H, which is the one that causes the release phase of the envelope to be entered, is particularly easy to understand because the amplitude and pitch parameters are ignored!

It's also worth pointing out that the bits work exactly as they did on the BBC Micro 33 years ago, so they are not exactly 'new fangled'. grin

Richard.
Re: CD-quality stereo SOUND!
Post by hitsware on Jun 11th, 2015, 11:43pm

>can I politely and gently suggest
>that it would be helpful if you did
>understand them.

Your manners and sweet disposition are appreciated, but most times accompanied by an over optimistic view of my abilities .............. smiley
Re: CD-quality stereo SOUND!
Post by dfeugey on Jun 12th, 2015, 08:35am

on Jun 11th, 2015, 11:43pm, hitsware wrote:
Your manners and sweet disposition are appreciated, but most times accompanied by an over optimistic view of my abilities .............. smiley

Mine too. I forget something very important: if HQSound lib is used once, then all the software will use it, even without the include. You must relaunch the IDE to come back to 8bit sound. HQSound is not a patch of your code, but a patch of BBC4Win runtime.

So to remove the first line after a first run is no use. You must remove it at first and add it later to hear the (big) difference.
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 12th, 2015, 09:06am

on Jun 12th, 2015, 08:35am, dfeugey wrote:
HQSound is not a patch of your code, but a patch of BBC4Win runtime

Well it's certainly a patch of my code, but apart from system DLLs (not a good idea to patch them!) the BB4W runtime is the only thing which can be patched. However it's important to appreciate that it's only the memory image that's being patched, not the EXE file itself.

Quote:
So to remove the first line after a first run is no use. You must remove it at first and add it later to hear the (big) difference.

That is documented in the library:

Code:
      REM If run from the BB4W IDE the patch persists for the entire session 

Of course the expectation is that you will run a program from the IDE only during its development phase; once it's fully tested and working it should be 'compiled' to a standalone EXE. At that point the issue is moot, since the patched memory image is unloaded as soon as the process terminates anyway.

If I had developed HQSOUND purely for use in the IDE there would have been no point in making it a CALLed module; I might just as well have made it an ordinary runnable program. But that's no use for patching a 'compiled' program.

Richard.
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 12th, 2015, 09:25am

Here's a simple demonstration of an ADSR envelope, including use of the H (hold) and F (flush) bits in the first parameter of SOUND.

To hear the effect hold down the space bar (substituting for a piano key) and then after a while release it again. Whilst the key is held down the Attack, Decay and Sustain phases of the envelope proceed automatically; in this example the sustain phase simply maintains a constant level. When the key is released the Release phase of the envelope commences:

Code:
      ENVELOPE 1,2,0,0,0,0,0,0,5,-4,0,-1,126,60
      oldspace% = FALSE
      REPEAT
        spacebar% = INKEY(-99)
        IF spacebar% <> oldspace% THEN
          oldspace% = spacebar%
          IF spacebar% THEN
            SOUND &0011, 1, 100, -1
          ELSE
            SOUND &0011, 1, 100, 0
            SOUND &1001, 0, 0, -1
          ENDIF
        ENDIF
        delay% = INKEY(1)
      UNTIL FALSE 

Richard.
Re: CD-quality stereo SOUND!
Post by dfeugey on Jun 12th, 2015, 10:23am

Quote:
That is documented in the library

We always complain of lack of documentation, but we never read it rolleyes
Anyway, thanks for all the explanations. Very useful library.

Re: CD-quality stereo SOUND!
Post by dfeugey on Jun 12th, 2015, 10:45am

Nota: I have a small noise when I begin to play something.
This noise is more present with the code of Meteor run.
http://www.bbcbasic.co.uk/bbcwin/tutorial/chapter19.html

Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 12th, 2015, 11:54am

on Jun 12th, 2015, 10:45am, dfeugey wrote:
Nota: I have a small noise when I begin to play something.

There's quite a nasty transient when the Windows waveOut subsystem is initialised, which is more noticeable when using HQSOUND. In part that's because the 16-bit samples are signed whereas the original 8-bit samples are unsigned, so the buffer gets initialised to an inappropriate value.

In principle the patching could be made more extensive, so that the buffer initialisation is also modified, but that's a fair amount of work just to reduce the audibility of the transient. Since it happens just once (unless your code contains a SOUND OFF, which is not recommended) a more practical solution is to add an initial delay of a second or so to allow the transient to decay before any 'real' music is output, e.g.:

Code:
      SOUND 0,0,0,20
      SOUND 1,0,0,20
      SOUND 2,0,0,20
      SOUND 3,0,0,20 

Richard.
Re: CD-quality stereo SOUND!
Post by hitsware on Jun 12th, 2015, 8:48pm

ENVELOPE to 0 .......... Only took 5 years :)

Re: noise
The main noise I hear is during a lone low note with attendant envelope. Like I'm hearing the steps.
HQSOUND seemed to help until I turn system gain up
enough to match no HQSOUND and the noise is back.
Code:
      REM   CALL @lib$+"HQSOUND"

      *TEMPO 133

      ENVELOPE 1,0,0,0,0,0,0,0,63,0,0,0,40,0
      ENVELOPE 2,0,0,0,0,0,0,0,127,0,0,-2,126,0
      ENVELOPE 3,0,0,0,0,0,0,0,127,-127,0,0,100,0
      ENVELOPE 4,0,0,0,0,0,0,0,0,0,0,0,0,0

      DIM orgn(11), bass(7), drum(7)

      FOR x=0 TO 11: READ orgn(x): NEXT x
      FOR x=0 TO 7: READ bass(x): NEXT x
      FOR x=0 TO 7: READ drum(x): NEXT x

      REPEAT
        FOR x=0 TO 11: FOR y=0 TO 7
            REM SOUND 0,1,orgn(x)+48,4
            REM SOUND 1,1,orgn(x)+76,4
            SOUND (4098-(bass(y)*4096)),2,orgn(x),1:SOUND 4098,2,0,3
            REM SOUND 3,drum(y),140,4
          NEXT y: NEXT x
      UNTIL FALSE: END

      DATA 32,24,4,32, 4,4,4,4, 24,24,4,4
      DATA 1,0,0,1, 1,0,0,0
      DATA 4,4,3,4, 4,4,3,4

 

Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 13th, 2015, 02:53am

on Jun 12th, 2015, 8:48pm, hitsware wrote:
Like I'm hearing the steps.

You may well be hearing the steps - SOUND has only 16 different levels (0-15) remember, which is quite coarse (they are 2dB steps I think). In fact you will probably hear the steps more clearly when using HQSOUND, since they aren't masked by quantising noise any longer!

I think you might find it helpful to consider the theoretical aspects of the BBC BASIC sound system (both with and without HQSOUND), rather than experimenting and trying to interpret what you hear. The beauty of digital audio is that everything is predictable, if you know the fundamental parameters (sampling rate etc.).

It's the same with all aspects of software really; trial and error is never the right way to do it. smiley

Richard.
Re: CD-quality stereo SOUND!
Post by hitsware on Jun 19th, 2015, 5:49pm

Richard,
For some reason your last message has disappeared ?

Good Oh ! ...... 2nd HQ works great ;D

How do I set ..

voice 0 left
voice 1 right
voice 2 & 3 center

Thank You .................

Code:
      REM Initialise stereo mix:
      M%!0 =  &40004000 : REM left 1,0
      M%!4 =  &00000000 : REM left 3,2
      M%!8 =  &00000000 : REM right 1,0
      M%!12 = &40004000 : REM right 3,2

 

Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 19th, 2015, 7:11pm

on Jun 19th, 2015, 5:49pm, hitsware wrote:
For some reason your last message has disappeared ?

It's still visible to me.

Quote:
How do I set ..

The REMs in the code you listed tell you. Just set the fields to the required gain values; there are eight 16-bit fields corresponding directly to the four 'left' gains and the four 'right' gains.

Richard.
Re: CD-quality stereo SOUND!
Post by hitsware on Jun 19th, 2015, 10:03pm

Greek to me ......... undecided
Re: CD-quality stereo SOUND!
Post by hitsware on Jun 20th, 2015, 01:14am

Dare to be great !
Put the 'balance' i.e. left/rightness
into the ENVELOPE command
In some of the bits that no one uses anyways ....
Re: CD-quality stereo SOUND!
Post by rtr2 on Jun 21st, 2015, 2:54pm

on Jun 19th, 2015, 10:03pm, hitsware wrote:
Greek to me ......... undecided

That's to be expected where I am today (Volos, Greece)!

Richard.

Re: CD-quality stereo SOUND!
Post by hitsware on Jun 21st, 2015, 3:14pm





Γεια σου