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

aquinch

  • Posts: 20
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: 22121
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: 20
Re: Wav Player - Noob question
« Reply #2 on: 6 Mar '19 - 22:27 »
Great. It did work. Thanks, Ian. Great job on the library!

Art60

  • Posts: 136
Re: Wav Player - Noob question
« Reply #3 on: 11 Nov '19 - 17:25 »
Hi aquinch,
Sorry to wake this thread.
I'd love to help you but I'm trying myself  to get basstest.c running within VisualStudioCode, with no luck either.
I previously built numerous Bass librairies based programs with Visual Basic but I have to speed up and been forced to rebuild my development from scratch (thank you W10).
So I'm here, with some Bass basic knowledge but unable to compile debug or run any example within that environment.
How did you manage to compile and run without errors?

Edit: I didn't read Ian's answer then yours telling your issue was fixed.
(just because I directly replied to your post from the results to my research within the website). Sorry.
If you ever come back here, please drop me a line or two if you think you can help me starting developping with Bass in Visual Studio Code (C/C++).
Thank you!
« Last Edit: 12 Nov '19 - 09:45 by Art60 »

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: Wav Player - Noob question
« Reply #4 on: 14 Nov '19 - 16:29 »
I haven't used Visual Studio Code myself, so I'm not familiar with setting up that, but if you're using Windows then you could use the regular Visual Studio version instead. Example projects for Visual Studio are included in the BASS package (see C\BASS.SLN). Alternatively, it looks like this might let you use Visual Studio projects with Visual Studio Code:

   https://github.com/fernandoescolar/vscode-solution-explorer