3

I have checked the BASS reference for a solution, but it was not to be found by me. My audio just does not want to play and yes, I checked if my speakers are working. Here is the "code":

#include "stdafx.h"
#include "D:\\Libraries\BASS\c\bass.h"
#include <iostream>
#include <cstdlib>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{   
    BASS_Init(-1, 44100, 0, 0, NULL);
    BASS_SetVolume(1);
    HSAMPLE sample = BASS_SampleLoad(false, "1.mp3", 0, 0, 1, BASS_SAMPLE_MONO);
    HCHANNEL channel=BASS_SampleGetChannel(sample, FALSE); 
    BASS_ChannelPlay(channel, FALSE); 
    system("pause");
    return 0;
}

I tried really different initialization setting etc. Nothing seemed to be working. The '1.mp3' file is in the debug folder of my "app". Thanks in advance!

Bizarre
  • 51
  • 1
  • 5
  • 1
    Check the result of each function call. If any fails, that should tell you what's going wrong. – Mike Seymour Sep 26 '14 at 22:26
  • BASS_Init returns 'true', so according to the reference it is working, however, it turns out that BASS_SampleLoad returns '0'. How is that, tho? Tried it with several mp3/wav files and was the same. – Bizarre Sep 26 '14 at 22:31
  • Checked it which BASS_ERROR flag it is on the BASS_SampleLoad call, and it says that it's the BASS_ERROR_FILEOPEN (can't open the file). Can't see why, tho. Reference says that it supports my file extension, and the music plays normally through another soft. – Bizarre Sep 26 '14 at 22:40
  • 1
    Perhaps wherever you've put the file isn't the working directory when the program runs. Try giving the full path. – Mike Seymour Sep 26 '14 at 22:43
  • It is not that. Went through it several times, changed the directory, wrote the full path, but the error remains unchanged. – Bizarre Sep 26 '14 at 22:45
  • is "BASS_ChannelPlay" supposed to return immediately, if so, can you see the threads BASS opened? Where's your BASS shutdown code? (Maybe after a reboot it's going to play?) If "BASS_ChannelPlay" is not supposed to return immediately, your `system("pause");` is not necessary. – St0fF Sep 26 '14 at 23:06
  • In what I understand it is supposed to return it as soon as u call it. The problem lies within the file reading part. – Bizarre Sep 27 '14 at 08:55
  • Tried out to CREATE a sample at a default frequency, and it does play normally with that code. I just don't know what to do to get the file loaded. – Bizarre Sep 27 '14 at 09:48

1 Answers1

-1

Sample for playing must be of void* type. Try as I did:

//path to file 
string *filePath = new string("/home/user/Qt-Projects/bass/sample.mp3");

Function to reduct to type void*:

const void* getFile(string* file){
    return file->data();
}

And finish:

streamHandle = BASS_StreamCreateFile(false, getFile(filePath), 0, 0, 0);
anothernode
  • 5,100
  • 13
  • 43
  • 62
Alex
  • 1
  • This is incorrect. The [documentation page](http://www.un4seen.com/doc/#bass/BASS_StreamCreateFile.html) shows you can use literal for file name `HSTREAM stream=BASS_StreamCreateFile(FALSE, "afile.mp3", 0, 0, 0);` – Killzone Kid Jul 31 '18 at 11:05
  • @KillzoneKid thank you I had been look for the docs page for a while – wij Aug 18 '22 at 23:16