Author Topic: Wav Player - Noob question  (Read 87 times)

aquinch

  • Posts: 13
Wav Player - Noob question
« on: 6 Mar '19 - 11:31 »
Hi,

I'm trying to get started with BASS but I'm not getting any sound output. This is my code:
Code: [Select]
//#include "windows.h"
//#include <commctrl.h>
//#include <stdio.h>


#include <iostream>
#include "bass.h"

using namespace std;

int main()
{
    if (BASS_Init(-1, 44100, 0, 0, NULL)) {
        printf("Init\n");
    }

    int stream = BASS_StreamCreateFile(FALSE, "CPerlStveFrne14.wav", 0, 0, 0);
    int error = BASS_ErrorGetCode();
    //cout << error;

    if (stream != 0) {
        //printf("Stream Open\n");
        // play the stream channel
        if (BASS_ChannelPlay(stream, false)){
            printf("Playing Stream\n");
        }
    }

    // free the stream
    BASS_StreamFree(stream);
    // free BASS
    BASS_Free();

    printf("Done\n");
    return 0;
}

This is my settings.json on MS Visual Studio Code, using Code Runner:
Code: [Select]
"code-runner.executorMap": {
        "cpp": "g++ $fullFileName bass.lib && a.exe"
    }

Compilation happens normally and I'm not getting any errors:
Code: [Select]
[Running] g++ "c:\Users\Ingo\Google Drive\1_myDrum\myDrum2_BASS\myDrum.cpp" bass.lib && a.exe
Init
Playing Stream
Done

[Done] exited with code=0 in 1.405 seconds

I'm using MinGW-w64 on Windows 10. Any help would be much appreciated. Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 21593
Re: Wav Player - Noob question
« Reply #1 on: 6 Mar '19 - 14:47 »
The issue there is that it is immediately freeing the stream (BASS_StreamFree) and output device (BASS_Free). You could add a getchar (or cin) call to delay that:

Code: [Select]
...
    // wait
    getchar();

    // free the stream
    BASS_StreamFree(stream);
    // free BASS
    BASS_Free();
...

If you would like to detect when playback has finished, you can poll BASS_ChannelIsActive, or set a BASS_SYNC_END sync via BASS_ChannelSetSync to receive notification. Please see the documentation for details on those functions.

aquinch

  • Posts: 13
Re: Wav Player - Noob question
« Reply #2 on: 6 Mar '19 - 22:27 »
Great. It did work. Thanks, Ian. Great job on the library!