BBC BASIC
« Auditory testing »

Welcome Guest. Please Login or Register.
Mar 31st, 2018, 10:46pm



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.
Cross-platform BBC BASIC (Windows, Linux x86, Mac OS-X, Android, iOS, Raspberry Pi)
BBC BASIC Resources
BBC BASIC Help Documentation
BBC BASIC for Windows Home Page
BBC BASIC Programmers' Reference
BBC BASIC Beginners' Tutorial
BBC BASIC for SDL 2.0 Home Page
BBC BASIC Discussion Group

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Auditory testing  (Read 141 times)
DDRM
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 36
xx Auditory testing
« Thread started on: Feb 9th, 2018, 3:33pm »

Hi Folks (probably mainly Richard!),

I'm interested in writing a program to demonstrate the effects of interaural delay (and maybe also loudness) on sound localisation. The basic SOUND statement together with TEMPO seems to limit control to around 1 centisecond (10 ms), but I think this will be too coarse: I'll probably need control at the 1 - 2 ms level. I've tried using TIMERLIB to achieve this:
Code:
      INSTALL @lib$+"TIMERLIB"      ON CLOSE:PROCTidyTimers:END      ON ERROR:PROCTidyTimers:END      INSTALL @lib$+"NOWAIT"      INSTALL @lib$+"HQSOUND"      PROC_hqinit      *TEMPO 1      REPEAT        PROCwait(100)        PROCsound(&1,-10,136,2)        timerid%=FN_ontimer(30, PROCPlayRight, 0):REM First parameter is delay in milliseconds        PROCwait(20):REM 20 centiseconds        PROC_killtimer(timerid%)      UNTIL FALSE      END      :      DEFPROCPlayRight      PROCsound(&3,-10,136,1)      ENDPROC      :      DEFPROCTidyTimers      PROC_killtimer(timerid%)      ENDPROC 

but the resolution limit still seems to be the *TEMPO 1 - if I set the timer to less than 10 ms I just get synchronous beeps. Between 10 and 20 I gradually get more and more beeps that are spaced by 10 ms, and fewer synchronous.

Am I doing something stupid/missing a trick here? Or will I need to go for something like the "real time audio" techniques listed on the wiki - I thought I could generate stereo data, but lag one channel behind the other by a very tightly controlled amount.

Given that the burst of audio required is only very short (a few ms), can I get away with a single buffer?

What happens when it runs off the buffer? Will it just stop, or do I need to make sure to do a WaveOutReset before it hits the end? If I want to repeat the sound, presumably I can just send it the same buffer again?

Will the stereo channels be sent "full left" and "full right"? I presume that's the case.

Just out of interest, as an aside, am I right in thinking BBC Basic is taking the data for the 4 sound channels, allowing for their stereo position, and then putting weighted sums into these two channels?

Would an equivalent, but easier, option be to create a stereo WAV file in memory, edit it appropriately, and then just play that?

Thanks for any help you can offer...

D
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Auditory testing
« Reply #1 on: Feb 9th, 2018, 8:14pm »

on Feb 9th, 2018, 3:33pm, DDRM wrote:
The basic SOUND statement together with TEMPO seems to limit control to around 1 centisecond (10 ms), but I think this will be too coarse

Yes, SOUND synthesises the waveform in 1 cs chunks (441 samples at 44.1 kHz) so it's impossible to generate a sound with a shorter period than that.

The most straightforward way of generating shorter bursts would be to use SYS "PlaySound" (in BB4W) or PROCPlaySound() (in BBCSDL, copied for example from xd2.bbc). In both cases playing the sound from memory rather than reading it from a file (SND_MEMORY flag in the former case) will minimise latency, although you may well find that a file is good enough once it's cached.

Richard.
« Last Edit: Feb 9th, 2018, 8:17pm by Richard Russell » User IP Logged

DDRM
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 36
xx Re: Auditory testing
« Reply #2 on: Feb 12th, 2018, 07:50am »

Hi Richard,

Thanks: I agree making a wav file in memory and then playing it looks a good solution - that way I can rewrite it on the fly to provide different delays. You pass the address of the start of the memory block (the beginning of the header?) as the first parameter, and then SND_Memory as the third? I'll give it a whirl.

I couldn't find xd2.bbc - I'm guessing that's for the PROCPlaySound()?

Best wishes,

D

User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Auditory testing
« Reply #3 on: Feb 12th, 2018, 08:58am »

on Feb 12th, 2018, 07:50am, DDRM wrote:
I couldn't find xd2.bbc - I'm guessing that's for the PROCPlaySound()?

It's in the top level of the XD2SDL.zip file, which you can still find at the original download address as published here before Christmas, or can also be found in the Multimedia folder of the Files section at the discussion group (accessible to members only).

Richard.
User IP Logged

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

| |

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