How to use FBSound loop?

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
rgwan
Posts: 41
Joined: Aug 19, 2011 17:41
Contact:

How to use FBSound loop?

Postby rgwan » Oct 22, 2011 5:45

for example,I have a wave file.
<-HEADER-><LOOP>
I want to get this effect.
first,play the Header section.
and play loop in the Loop section.
I probably to change the pitch.
So,how can i do.
creek23
Posts: 261
Joined: Sep 09, 2007 1:57
Location: Philippines
Contact:

Postby creek23 » Oct 22, 2011 10:31

FBSound loops the whole sound -- not just a portion.
TJF
Posts: 3604
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Oct 22, 2011 12:52

You can split the sound into two sections. Play first section once and loop the second one.
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Postby maddogg6 » Oct 22, 2011 16:38

loops can come in basically in 2 flavors;

if these loops are 'inter sample' as in "wavetable synthesis", to allow for an unlimited sustain to a sounds envelope;

simply 'looping' (like described), while technically possible, is musically unusable.

Look into 'wave table synthesis sample tuning' and is NO simple feat and requires some DSP knowledge to do and still be musically usable.

For that I would be googling sample tuning techniques and ask DJ different Q's how to implement them as I think FB sound can be useful for that.

OR

If these loops are of musical phrases, or sound effects - timing is/may be still critical, but you can get usable results even without any DSP knowledge (no sample tuning needed).

For that, (I am pretty sure) you need to use a thread to control timing and use other thread(s) to play the sounds.

edit:
Upon re-reading your post - it is clearer to me now you are looking at 'sample tuning'.

After looking into those techniques; as TJF suggested - load those 'segments' into memory, and 'looping' the 'segment' as many times as needed (or a minimum # of times), re triggering that segment if you cant know that # ahead of time (to specify # of loops, use a 'minimum' loop - again depends on the sample/circumstances).

Again, I am pretty sure you will need to use a thread to control all the timing, and another to play the samples.

edit2
Forgot to mention;
Once you have the timing worked out, apply the pitch shifting DSP effect to it to change pitch.
rgwan
Posts: 41
Joined: Aug 19, 2011 17:41
Contact:

Postby rgwan » Oct 23, 2011 6:10

Thanks.
But I don't know who function can split wave and how to create WAVE file.
For example:
I have two WAVE file for piano.
C1 and C2
I will use fbs_Set_SoundSpeed() to change the pitch to play "An die Freude" .
For example.
I get C#1 will use fbs_Set_SoundSpeed(hSnd,1/12 *2)
I get D1 will use fbs_Set_SoundSpeed(hSnd,2/12*2)
I can listen it for my speaker.But I can 't save the WAVE.
rgwan
Posts: 41
Joined: Aug 19, 2011 17:41
Contact:

Postby rgwan » Oct 23, 2011 6:51

Here is my Huan le Song program.

Code: Select all

'  #############
' # test7.bas #
'#############

' example of:
' fbs_Set_PlugPath()
' fbs_Init()
' fbs_Get_PlugRate()
' fbs_Load_MP3File()
' fbs_Play_Wave()
' fbs_Set_SoundSpeed() !!!

#libpath "../lib"
#include "../inc/fbsound.bi"

const plug_path = "../lib/"
const data_path = "../data/"

' only if not same as exe path
fbs_Set_PlugPath(plug_path)

dim as FBSBOOLEAN ok
ok=fbs_Init()
if ok=false then
  ? "error: fbs_Init() !"
  ? fbs_get_plugerror()
  beep:sleep:end 1
end if

dim as integer hWave
ok=fbs_Load_MP3File("C1.mp3",@hWave)
if ok=false then
  ? "error: fbs_Load_MP3File() !"
  beep:sleep:end 1
end if

dim as integer hSound

'play wave endless and create new sound object from wave object
'ok=fbs_Play_Wave(hWave,-1,,,,@hSound)
'if ok=false then
'  ? "error: fbs_Play_Wave() !"
'  beep:sleep:end 1
'end if

'
' main
'

? "Playing Huanlesong."


Dim i As integer
Dim speed as single
'while 1

/'For i = 0 to 12
ok=fbs_Play_Wave(hWave,,,,,@hSound)
      speed=(i/24)*2+1
      print speed
      fbs_Set_SoundSpeed hSound,speed
  sleep 1000
fbs_Set_SoundPaused hSound,True
Next i

'/

Dim huanlesong(14) As integer
'C #C D #D E F #F G
huanlesong(0)=4 '3
huanlesong(1)=4 '3
huanlesong(2)=5 '4
huanlesong(3)=7 '5
huanlesong(4)=7 '5
huanlesong(5)=5 '4
huanlesong(6)=4 '3
huanlesong(7)=2 '2
huanlesong(8)=0 '1
huanlesong(9)=0 '1
huanlesong(10)=2 '2
huanlesong(11)=4 '3
huanlesong(12)=4 '3
huanlesong(13)=2 '2
huanlesong(14)=2 '2
For i = 0 to UBound(huanlesong)
ok=fbs_Play_Wave(hWave,,,,,@hSound)
      speed=2^(huanlesong(i)/12)
      print speed
      fbs_Set_SoundSpeed hSound,speed
  sleep 1000
fbs_Set_SoundPaused hSound,True
Next
? "End"
end

I want to record it sound to another WAVE file.Can you help me ,TJF?
rgwan
Posts: 41
Joined: Aug 19, 2011 17:41
Contact:

Postby rgwan » Oct 23, 2011 7:31

maddogg6 wrote:loops can come in basically in 2 flavors;

if these loops are 'inter sample' as in "wavetable synthesis", to allow for an unlimited sustain to a sounds envelope;

simply 'looping' (like described), while technically possible, is musically unusable.

Look into 'wave table synthesis sample tuning' and is NO simple feat and requires some DSP knowledge to do and still be musically usable.

For that I would be googling sample tuning techniques and ask DJ different Q's how to implement them as I think FB sound can be useful for that.

OR

If these loops are of musical phrases, or sound effects - timing is/may be still critical, but you can get usable results even without any DSP knowledge (no sample tuning needed).

For that, (I am pretty sure) you need to use a thread to control timing and use other thread(s) to play the sounds.

edit:
Upon re-reading your post - it is clearer to me now you are looking at 'sample tuning'.

After looking into those techniques; as TJF suggested - load those 'segments' into memory, and 'looping' the 'segment' as many times as needed (or a minimum # of times), re triggering that segment if you cant know that # ahead of time (to specify # of loops, use a 'minimum' loop - again depends on the sample/circumstances).

Again, I am pretty sure you will need to use a thread to control all the timing, and another to play the samples.

edit2
Forgot to mention;
Once you have the timing worked out, apply the pitch shifting DSP effect to it to change pitch.

I will only get 32 max.polyphone.So my program is not too fit into memory and cpu.
TJF
Posts: 3604
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Oct 23, 2011 8:44

rgwan wrote:I want to record it sound to another WAVE file.Can you help me ,TJF?

Sorry, I don't understand what you're trying to do. And I'm no fbsound expert, I just used it once in a little demo six month ago. All my knowledge I got from the documentation and the source.
rgwan
Posts: 41
Joined: Aug 19, 2011 17:41
Contact:

Postby rgwan » Oct 23, 2011 9:58

I want to make a midi synthesizer.
it can change wave pitch and save sound in wave file.or play to speaker.
oh.my english is very poor.....
podvornyak
Posts: 148
Joined: Nov 12, 2007 11:46
Location: Russia

Postby podvornyak » Oct 23, 2011 12:14

It is just sound library... not editor... Pitching sound don't mean change audio data. Sound data stay the same. You should check PCM sound data type. It is raw audio data. http://en.wikipedia.org/wiki/PCM
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Postby maddogg6 » Oct 23, 2011 14:54

rgwan wrote:I will only get 32 max.polyphone.So my program is not too fit into memory and cpu.

For looping samples like that - IFAIK you have to load them into memory - or re-invent the wheel somehow.

Like writing to disk and playback - perhaps like a looped tape recorder - or TRAM (circular memory in SBLive DSP to make Time based effects like reverb, delay, chorus, flanger - all have feedback loops that get delayed - TRAM memory addressed this complication in hardware. Using HDD will just slow you down tho and if your PC is already modest... ??? .

But if your memory and cpu is limiting how many polyphony you can get (which is the only way I can understand how you came up with this #), and that # is 32 - your experiencing what I call in nostalgia.... "too weak of PC to accomplish your musical goals". So the SSD is not likely a candidate. You need other stuff first, memory and CPU for instance.
TJF
Posts: 3604
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Oct 23, 2011 15:00

rgwan wrote:I want to make a midi synthesizer.
it can change wave pitch and save sound in wave file.or play to speaker.
oh.my english is very poor.....

For a synthesiser you just need to generate the sound itself. Create an empty sound object and fill it with data (ie a sinus wave: frequency = tone height, amplitude = volume). Then use fbsound to play the result.

AFAIK fbsound cannot save files so you have to code this yourself (you can learn from fbsound by reversing the load algorithm).
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Postby maddogg6 » Oct 23, 2011 15:21

rgwan wrote:Thanks.
But I don't know who function can split wave and how to create WAVE file.
For example:
I have two WAVE file for piano.
C1 and C2
I will use fbs_Set_SoundSpeed() to change the pitch to play "An die Freude" .
For example.
I get C#1 will use fbs_Set_SoundSpeed(hSnd,1/12 *2)
I get D1 will use fbs_Set_SoundSpeed(hSnd,2/12*2)
I can listen it for my speaker.But I can 't save the WAVE.

that because you did not store that change in memory - FB sound is just changing playback speed.

You need to either cause that change to be stored in memory (and store that to HDD) - or render a 'performance' to a wav file with something like windows sound recorder and windows mixer set up to record 'what you hear' while you run your program.

Simply changing speed is not the best way to do pitch shifting btw, I think DJ put a pitch shifting DSP plugin in FBSound.. Id be looking at that first off as there is some filtering that can help make the pitch shifting sound a little more natural.

But ok...
regarding looping;
Assuming this is a lesson in audio for you, it looks like you need to 'get' and 'set' the play position during playback;

fbs_Get_SoundPointers (hSound,@lpStart,@lpPlay,@lpEnd) as FBSBOOLEAN
fbs_Set_SoundPointers (hSound,lpStart,lpPlay,lpEnd) as FBSBOOLEAN

Timing will be important (and still sound like a piano), as it goes beyond my grasps, it's all I can say on that. you would need to translate those loop points you have into memory locations and probably their pointers - some how. I don't see that DJ accounted for those stored loop points in WAV files.
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Postby maddogg6 » Oct 23, 2011 15:28

TJF wrote:
rgwan wrote:I want to make a midi synthesizer.
it can change wave pitch and save sound in wave file.or play to speaker.
oh.my english is very poor.....

For a synthesiser you just need to generate the sound itself. Create an empty sound object and fill it with data (ie a sinus wave: frequency = tone height, amplitude = volume). Then use fbsound to play the result.

AFAIK fbsound cannot save files so you have to code this yourself (you can learn from fbsound by reversing the load algorithm).

Speaking in more ignorance of FB/FBSound than audio, I'm pretty sure you would read the data from memory (get pointers, do pointer math) - recreate what ever header (wav), compress (mp3/ogg) and store to HDD.

But yeah FBSound is more aimed at games than DAW. But the twain do meet for sure.
rgwan
Posts: 41
Joined: Aug 19, 2011 17:41
Contact:

Postby rgwan » Oct 24, 2011 11:23

maddogg6 wrote:
rgwan wrote:I will only get 32 max.polyphone.So my program is not too fit into memory and cpu.

For looping samples like that - IFAIK you have to load them into memory - or re-invent the wheel somehow.

Like writing to disk and playback - perhaps like a looped tape recorder - or TRAM (circular memory in SBLive DSP to make Time based effects like reverb, delay, chorus, flanger - all have feedback loops that get delayed - TRAM memory addressed this complication in hardware. Using HDD will just slow you down tho and if your PC is already modest... ??? .

But if your memory and cpu is limiting how many polyphony you can get (which is the only way I can understand how you came up with this #), and that # is 32 - your experiencing what I call in nostalgia.... "too weak of PC to accomplish your musical goals". So the SSD is not likely a candidate. You need other stuff first, memory and CPU for instance.

I used fluidsynth to get 256.

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 5 guests