20 Jun '13 - 04:34 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Simple example for c++  (Read 936 times)
coderm
Posts: 5


« on: 15 Aug '12 - 03:03 »
Reply with quoteQuote

Hi,

Is there a simple "hello world" example somewhere I can look it?

I tried searching and through the examples that come with the download but it doesn't include a simple "hello world" type example.

Perhaps someone can help me.


Thanks.
Logged
Ian @ un4seen
Administrator
Posts: 15366


« Reply #1 on: 15 Aug '12 - 17:02 »
Reply with quoteQuote

In order to tell which functions you would need, please confirm what you would like to do with BASS. For basic playback of an audio file, the bare bones code would look something like this...

BASS_Init(-1, 44100, 0, hwnd, 0); // initialize default output device
stream=BASS_StreamCreateFile(FALSE, filename, 0, 0, 0); // create a stream to play an audio file
BASS_ChannelPlay(stream, FALSE); // start playing it

...

BASS_StreamFree(stream); // free the stream
BASS_Free(); // free the output device

Details on the aforementioned functions (parameters/etc) can be found in the documentation.
Logged
coderm
Posts: 5


« Reply #2 on: 15 Aug '12 - 19:09 »
Reply with quoteQuote

Thanks for the reply.

All I really wanna do it have it play sounds. I was gonna go for the ogg type files. Get the best quality at the least cost I guess. At about 44100, 192k, 16bit, 2 channel stereo.

Its an extension for another project, non-commercial of course.
Logged
coderm
Posts: 5


« Reply #3 on: 15 Aug '12 - 21:48 »
Reply with quoteQuote

I have a few more questions.

How can I add a handle so it will wait will it stopped playing the sound?

Is there a way to load some files into memory?

I have looked at the documentation and still am.
Logged
Ian @ un4seen
Administrator
Posts: 15366


« Reply #4 on: 16 Aug '12 - 15:08 »
Reply with quoteQuote

How can I add a handle so it will wait will it stopped playing the sound?

The BASS_StreamFree call will stop playback of the stream. If you would like to delay that until playback has finished, you could use a BASS_SYNC_END sync, which will notify you when playback has reached the end, something like this...

BASS_ChannelSetSync(stream, BASS_SYNC_END, 0, EndSyncProc, 0); // set an END sync on the stream
BASS_ChannelPlay(stream, FALSE); // start playing it

...

void CALLBACK EndSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
BASS_StreamFree(channel); // free the stream
}

Alternatively, you could add the BASS_STREAM_AUTOFREE flag to the BASS_StreamCreateFile call to have the stream automatically freed when it reaches the end. Please see the documentation for details on that stuff (also see BASS_ChannelIsActive).

Is there a way to load some files into memory?

Do you mean pre-decode the files to memory, so that no file reading or decoding is required during playback? If so, that is possible via the "sample" functions (see BASS_SampleLoad).
Logged
coderm
Posts: 5


« Reply #5 on: 17 Aug '12 - 06:46 »
Reply with quoteQuote

What I more meant was some sort of a wait/block handle to wait till its finished.

Because as it stand now I need to use "std::cin.get()" for it to wait till its finished. And if I don't then the program will just exit.

Another question, is BASS able to play multiple sounds at once? I was planning on playing sound through running threads and thus sounds may be played at the same time.

Is that possible?
Logged
Ian @ un4seen
Administrator
Posts: 15366


« Reply #6 on: 17 Aug '12 - 17:58 »
Reply with quoteQuote

What I more meant was some sort of a wait/block handle to wait till its finished.

If you're using Windows, you can use an "event" for that, eg. CreateEvent. Something like this...

BASS_ChannelSetSync(stream, BASS_SYNC_END, 0, EndSyncProc, 0); // set an END sync on the stream
waitevent=CreateEvent(0, 0, 0, 0); // create an event
BASS_ChannelPlay(stream, FALSE); // start playing the stream
WaitForSingleObject(waitevent, INFINITE); // wait for the event to be set

...

void CALLBACK EndSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
SetEvent(waitevent); // set the event
}

Another question, is BASS able to play multiple sounds at once? I was planning on playing sound through running threads and thus sounds may be played at the same time.

Yes, you can add BASS_StreamCreateFile and BASS_ChannelPlay calls for each extra file.
Logged
coderm
Posts: 5


« Reply #7 on: 21 Aug '12 - 08:34 »
Reply with quoteQuote

Is there a static lib/dll available? So I won't have to export a .dll extra with my project.
Logged
Chris
Posts: 1507


« Reply #8 on: 21 Aug '12 - 11:59 »
Reply with quoteQuote

The Answer is no.
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines