playing ogg-files as chords - multichannel sound?

Littlun

Member
Licensed User
:sign0085:

Hi there,

I am trying to write a little eartraining program. The idea is to load a chromatic scale of ogg-files into an array and then play intervals, chords or scales. To add some "feeling" to the music I would like to put the playing thread asleep with different values (e.g. longer ones at the end (let ring...)). I didn't have any problem getting the FMOD-library to work with single notes each played separately, but trying something like that

player1.Play(AppPath & "\dSharp.ogg")
player1.Play(AppPath & "\c1.ogg")

only plays the c1.ogg file; the dSharp is simply skipped. Putting a sleep(someTime) statement in between these lines only gives strange results, too (stopping the first sound some strange time (not corresponding to the 'someTime' in the sleep-statment) in between).

I did some tests on another IDE which allows the user to init the sound-engine with multichannel-play (the other IDE doesn't run stable at all and does not compile what it promises that it should, so I would like to stick to b4p).

Now my questions are: Is there any way to program multichannel wav/ogg-output with b4p? If so, does anyone have an idea how to run the playing in a second thread in order to let the exercises run continously but still being able to stop them?

Any help would be appreciated

tnx in advance

littlun
 

mjcoon

Well-Known Member
Licensed User
I'm not sure what you mean by "I would like to put the playing thread asleep with different values".

FMOD runs asynchronously, so once started it keeps going until you stop it or the file finishes, or you replace the playing file with a new one. Your program will continue to run and can present the user with a "Stop" interface, alter the volume, and so forth. Hence your "sleep" has no direct effect.

I don't know anything about OGG files. Are you constructing them on the fly? Isuppose it would be rather hard work (for the PPC!) to construct WAV files on the fly using added sine waves of the required frequencies!

I have already determined for myself that FMOD won't play MIDI files on a PPC (while the PC version does).

The experiment of using two players seems interesting, but I would not put money on it doing what you want... :sign0013:

Mike.
 

LineCutter

Active Member
Licensed User
Longtime User
What B4PPC could use is a command like you used to get in the olden days that will create a tone with a given frequency, attack, decay & duration. Playing those in parallel would cover simple chords.
Until someone writes FFT.dll & makes it run fast enough to be of use on a PPC I think that more advanced playback of recordings will remain beyond us.
 

Littlun

Member
Licensed User
Hi there,

thanks for the replies.

I had tried it with more than one player-objects already, but it didn't do the trick.


Here is more of what I want it to be like: I want to include a start/stop-button to get a loop going. This loop should run within its own thread so I would be able to set a stopFlag from the stop-buttons click-method and actually stop the replay.

Sub Globals
'Declare the global variables here.
stopFlag = False
counter = 0
End Sub

Sub App_Start
Form1.Show

player1.New1
player2.New1
End Sub


Sub Button1_Click
stopFlag = True
End Sub

Sub Button2_Click
stopFlag = False
play
End Sub

Sub play
Do Until (stopFlag = True OR counter >= 4 )
player1.Play(AppPath & "\dSharp.ogg")
Sleep(1500)
player2.Play(AppPath & "\c1.ogg")
Sleep(3000)
counter = counter + 1
Loop
End Sub


So far only the counter value will stop the loop (which is what I would the code expect to do, too). I just found a hint on a thread-dll from agraham in the handbook, so I will take the time to test that. Maybe putting each player object in its own thread will do the trick. I'll be back on this, as soon as I get my first results - which might take a couple days, as programming that software is supposed to support me in playing my music, not to replace it.

The code above would do the trick in order to play a scale or an interval. Strange thing is, that it does not work without the last "sleep(3000)" statement (resulting in only the first note played, the second one skipped). The last note is supposed to sound a little longer (like when the fat lady practices scales), so the sleep-value is higher.

As I mentioned before, I developed the code from within another IDE but the other IDE doesn't compile the classes and methods correctly when it comes to the mobile device (I know, there is always a workaround, but I want to have an object-oriented model). I have a rough draft of a windows version from within the other IDE up and running. Though the principles behind the desktop-version (especially the sound-output) do work on the mobile draft, too.

The ogg-files were created before hand, using a midi-sequencer-software and a converter. The idea behind using the ogg-files was that I get a decent sound result on any device and the ogg-files turned out to be smaller than mp3-files. So I preferred it in order to be able to deploy the software in a tiny (wow, my first hard-disk had 52 MB and that was a lot!) package. Using the range of 3 octaves I get 37 ogg-files with a size of 23 k in average. I did not get into the ogg-format, it simply worked from within the other IDE.

Even though I would appreciate to have an FFT.dll, I don't think that it would suit my purposes, as I need a special wave-form. From what I read, mod-files would be 1st choice, as it seems to be possible to store the wave-form and the played notes seperately. But then again, I didn't dig into that to deep...

Littlun
 

mjcoon

Well-Known Member
Licensed User
I had tried it with more than one player-objects already, but it didn't do the trick.

So what did happen?

I think that you should stop using "sleep" and use timers instead. I raised a forum query myself when I discovered that it is not possible to interrupt a sleep() by pressing a key. Timers are much more flexible, and possibly more accurate.

I know that the device can cope with two sound outputs at once because I can have my Basic4PPC "Music Player" running at the same time as SatNav, and the SatNav just shouts over the music. As an experiment it might be worth trying to start FMOD and then see if you can use the Basic4PPC function Sound() on a WAV file at the same time.

Good luck with threading...

Mike.
 

Littlun

Member
Licensed User
Hi again,

well, the threading didn’t work and wav-files do not do the trick either (even though it's always a good advice to go back to the basics, so thanks for that). I tried using a simple thread-application, started two note-threads with button-click-methods. The first thread was interrupted immediately when I started the second thread. The second thread played the note for the sleep-time and then the program switched between both threads with the first thread’s playing-time being the exact copy of the interruption. So there seems to be more to it than just the threads locking the play-method

The next idea is the use of processes. It kinda works on the desktop, you can see the code below. The question is, if I can pass command-line-arguments with b4p and the process.Start-method. Does anybody know?

B4X:
Sub App_Start

Form1.Show
processPlayer1.New1
processPlayer2.New1
processPlayer3.New1

End Sub


Sub bnStartCounter1_Click
'play chord
processPlayer1.Start("player.exe")
processPlayer2.Start("player2.exe")
processPlayer3.Start("player3.exe")

End Sub
The player-process is something like that, compiled to a windows.EXE

B4X:
Sub App_Start
player.New1
Player.Play(AppPath & "\e1.ogg")
Sleep(1000)
End Sub

Another question is, does anybody know what the mode-parameter-values of the play2-method of the FMOD-library are. I couldn't figure it out from the fmod page linked from the library help file.

Mike, the sleep-method isn't really my problem, as I don't want the played note to be interrupted as long as the specific thread is asleep. I try to realize a simple note-duration using the sleep-method.

Littlun
 

Louis

Active Member
Licensed User
Longtime User
Hi. Hekkus will do exactly what you want and is compatible with B4PPC, it does .wav and .ogg files and has multiChannel sound capabilities. Look here:
http://www.b4x.com/forum/additional-libraries/1219-new-hekkus-sound-library-wrapper.html
In that forum topic is a general example of how to mix and match multiple sounds. If you have problems with OGG then revert back to wave and you can use either compressed or uncompressed waves, 8 or 16 bit. HTH.
 

Littlun

Member
Licensed User
Hi Louis,

I'm afraid I didn't get your library to run.

I used any combinations of the Net-library, the non-Net-Library, the new hss.d-files and the old ones, but at least the desktop-version doesn't run (I didn't check on the device-version yet)

I also tried it with wav and ogg-files, which made no difference. The main error-message is the following:

unable to find an entry-point named 'hssSound_loadFile' in DLL 'hssDesktop.d'

None of your samples compile on my desktop either (once again, I didn't try the mobile-device-version).

:sign0013: but do you have another hint?

Littlun
 

Louis

Active Member
Licensed User
Longtime User
Hi. Make sure both HSSNETDesktop.dll and HSSDesktop.d are copied into the same folder and make a reference to HSSNetDesktop.dll. Wave seems to work fine, but I am also having the same issue with .OGG. If you still have trouble let me know and I'll post a fix. HTH.
 

Littlun

Member
Licensed User
Hi Louis,

it took me some time to get back to the project.

I had tried it in any way I could think of, including "wav-files", but I couldn't get it to work.

If you would still have another idea how to get it to work, I would appreciate you sharing it with me.

TNX in advance.
 

Chebu

Member
Licensed User
Longtime User
Hi Louis and Littlun. I'm in the same situation as Littlun, it is not possible to load any file because it is impossible to find the entry point in the original library, .d. Will be this solved?

I need to use Hekkus library because I have to change frenquency, speed and other parameter and FMOD implemented in B4P not allows this so I think there is not any other way. Is there any possibility to use the .NET library of Hekkus, directly? Use of pointers for Channel Class, New, is solved?

Do you know any other library with wrapper for B4P or a directly compatible library similar to Hekkus?

Many thanks.
 

Louis

Active Member
Licensed User
Longtime User
Hi. Here are fixed .d files. Sorry for any inconveniences. These are temporary fixes until I get the chance to re-wrap the .NET libraries for Basic4ppc. This for now only allows .wav files. HTH.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…