Hi there, I started using the library today - fantastic. I've got 90% of what I need to get done - done, however I've found one problem that I can't resolve.
I'm using a C# application with BASS.Net (v2.4, downloaded 23DEC2014). I'm using the Mono framework, and it's all running on Arch Linux on a Raspberry Pi.
The BASS 2.4 library was also downloaded from this site on the same day.
If I use the Windows BASS.Net and BASS libraries, my little console test application works perfectly on windows.
If I switch the .NET reference to the BASS.Net.Linux library and run it with mono on Linux, it has a small problem. Based on the fact that the same code works on Windows - I'm wondering if this is an issue with the library on ARM Linux. I couldn't find a previous version of the library to try however.
Here's a quick rundown of the code. For reasons that don't really matter to the problem, I'm:
1. receiving a small segment of audio data via a TCP stream into a byte array.
2. determining the size of that audio data, and then putting the byte array into a memorystream.
3. using BASS_StreamCreate and a STREAMPROC to read the data from the memorystream.
This works perfectly! The whole thing then repeats waiting for the next audio stream to come in over the network. Here's where the problem starts.
On windows, it simply plays the second stream, and the third, and fourth etc. On Linux, the screen output *looks* like it's working properly, but I don't hear any audio. In fact, the only way I can get the code to play audio the second/third/fourth time - is if I call BASS_Free() and then re-call BASS_Init() after I play each stream. Windows - its fine though. Ideally I want to be able to keep playing audio streams without having to reinitialize the BASS library each time.
Really appreciate the help - I can't work out what I'm doing wrong. I've also tried:
1. Push streams - re-using the one stream, and then just sending more push data as new audio comes in from the network.
2. Push streams - creating and releasing a new stream each time.
3. pausing/resuming stream after each occurrence.
4. checking if stream is stalling/running properly - which it appears to. it stalls after the first audio stream has finished, then once more data comes in it runs again.
All of these have the same result - it reports that its working correctly, but I just don't hear any audio after the first stream has played.
Here's the code. It is messy - this is purely the 'proof of concept' test code before I turn it into something pretty and error checking, good practices etc.
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Runtime.InteropServices;
using Un4seen;
using Un4seen.Bass;
using Un4seen.BassAsio;
using Un4seen.BassWasapi;
namespace SpeechTestHarness
{
class Program
{
static NetworkStream networkStream;
static int iAudioSize;
static MemoryStream _fs;
private static STREAMPROC _myStreamCreate;
private static byte[] _data = null;
private static int MyFileProc(int handle, IntPtr buffer, int length, IntPtr user)
{
Console.WriteLine("MyFileProc()");
if (_data == null || _data.Length < length)
_data = new byte[length];
int bytesread = _fs.Read(_data, 0, length);
Marshal.Copy(_data, 0, buffer, bytesread);
if (bytesread < length)
{
bytesread |= (int)BASSStreamProc.BASS_STREAMPROC_END;
networkStream.Close();
}
return bytesread;
}
static void Main(string[] args)
{
Un4seen.Bass.BassNet.Registration("email", "key");
if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
Console.Write("BASS_Init() failed");
while (true)
{
// Endless loop
run();
}
//Bass.BASS_Free();
}
static void run()
{
byte[] bytes;
byte[] btSize = (byte[])Array.CreateInstance(typeof(byte), 4);
int iCounter = 0;
TcpClient tcpClient = new TcpClient();
Console.WriteLine("run");
_myStreamCreate = new STREAMPROC(MyFileProc);
// Get Audio Stream
tcpClient.Connect("172.16.51.20", 64004);
networkStream = tcpClient.GetStream();
// First 4 bytes contain size of audio segment
if (networkStream.Read(btSize, 0, 4) != 4)
{
Console.WriteLine("run - couldn't get audio size");
return;
}
iAudioSize = BitConverter.ToInt32(btSize, 0);
Console.WriteLine("Audio Size: " + iAudioSize.ToString());
// Allocate overly large receive buffer
bytes = new byte[1280000];
while (iCounter < iAudioSize)
{
// read 32k chunk
int z = networkStream.Read(bytes, iCounter, (int)32000);
iCounter += z;
}
_fs = new MemoryStream(bytes, 0, iAudioSize);
// create stream
int channel = Bass.BASS_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT, _myStreamCreate, IntPtr.Zero);
Bass.BASS_ChannelPlay(channel, false);
// wait for audio to finish
System.Threading.Thread.Sleep(3000);
Bass.BASS_StreamFree(channel);
}
}
}