CreateAudioSample

BlitzMax Forums/BlitzMax Programming/CreateAudioSample

MACCB(Posted 2013) [#1]
Hi

This is what the manual says about CreateAudioSample:

' createaudiosample.bmx

Local sample:TAudioSample=CreateAudioSample( 32,11025,SF_MONO8 )

For Local k=0 Until 32
sample.samples[k]=Sin(k*360/32)*127.5+127.5
Next

Local sound:TSound=LoadSound( sample,True )

PlaySound(sound)

Input

I have a few questions:

1) What does the last bit "SF MONO8" really mean and what do the other options do?

2) This example plays one sample, is it possible to play two or more samples and once and syncronise when they start playing?

3) Is the length of the sample limited to memory available?

Grateful for any help. Please go easy on me I am new to these commands.

Thanks

M


Brucey(Posted 2013) [#2]
1) Sound Format? 8-bit mono. As opposed to say, 16-bit stereo.

3) It probably depends on which audio driver you are using. There are some drivers that support streaming.


MACCB(Posted 2013) [#3]
But there are six different options. What do they mean, I.e. what is the difference between each etc.

Anyone any ideas on 2)???

Thanks

M


Floyd(Posted 2013) [#4]
It must be the sampling rate, the numbers of "data points" per second.

11025, 22050 and 44100 are common values. The last one, 44100, is typical for 16-bit stereo.

In fact I have now checked http://blitzbasic.com/bmdocs/command.php?name=CreateAudioSample&ref=goto
and I guessed correctly.


MACCB(Posted 2013) [#5]
Ok. So what about the question 2)

Thanks

M


AdamStrange(Posted 2013) [#6]
1.
CreateAudioSample( 32,11025,SF_MONO8 ) can be translated as:

CreateAudioSample(length (in frames), hertz, format )
- a frame is a single mono/stereo audio value, it will either be 8bit or 16 bit
if the format is stereo then the frame contains two values (left and right)
if the format is mono it contains a single value

2.
yep, no problem.
- TChannel actually plays a Tsound object
- TSound contains a TSample object
Although there are no documents to how many channels are available, digging into the source reveals the possibility of up to 1024 channels. I'm not sure how many in practice, but Max can handle 32 channels with no problems

3.
Yep, there are limits. Max is 32bit so in theory the maximum memory should be 2gig. I've done some quick tests (mac) and got 3gig of samples loaded at one time


Brucey(Posted 2013) [#7]
Yep, there are limits.

There certainly are limits to the available memory, but if you are streaming your audio, for example an mp3 from the harddrive, you can have more sound data than available memory.


MACCB(Posted 2013) [#8]
Adam

Many thanks. Very helpful.

On 1. how can a frame have more than one value? The example gives each frame a value "sample.samples[k]=Sin(k*360/32)*127.5+127.5", how could you have two values going to the same [k]?

On 2. Could you tell me how you would amend the example to use TChannel instead.

Thanks so much guys.

M


AdamStrange(Posted 2013) [#9]
no probs

1..
a sound can be;
mono = one value
or stereo = two values (left and right)

so a frame is a single slice of a sound (either mono or stereo)
- so a frame can have one value (mono) or two values (stereo)

in practice you don't need to deal with frames if your sound is mono as a frame and a value are the same thing

When you have a stereo sound, everything need to be doubled as each frame is two values


- the computer doesn't deal with 'frames' but a 'stream' of data.
(lets assume that you are dealing with 8bit sound to make things simple)

our audio stream is
[1] [2] [3] [4] [5] [6] [7] [8] [9]..

where each number is a frame and each frame is mono8bits and it's sent out as mono

if we were dealing with stereo, we pack TWO numbers together to form the frame;

[1,50] [2,49] [3,47] [4,46] [5,44] [6,42] [7,39] [8,36] [9,32]
where each PAIR of numbers is a frame and each frame isstereo8bits.

Yep, I know it's confusing, but you just need to take a leap of faith and think "how is it stored"

when you move into 16bit, you are dealing with larger stream sizes but the principles remain the same.

2..
PlaySound(sound) is the same as:

Local Channel:TChannel = AllocChannel()
PlaySound sound, channel


Midimaster(Posted 2013) [#10]
' load audio file:
Audio=LoadSound("Piano.ogg")

' alloc and pre-settings:
Channel = CueSound( Audio,Null )	
SetChannelVolume Channel, 0.5

' start playing now:
ResumeChannel Channel