Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - farw

Pages: [1]
1
Audio / Trouble with feeding audio stream
« on: July 11, 2009, 05:38:33 pm »
It works now. I had to divide the number of NbSamples by the size of sf::Int16. Now it looks like that
Code: [Select]
bool player::OnGetData(sf::SoundStream::Chunk& ck)
{
    for (unsigned got = 0; got < in_size; ++got)
    {
        char* temp = in + got; // inkrement the pointer
        *temp = data_stream->recieve_byte(); // get a byte of the audio stream
    }

    size_t decoded_bytes;
    mpg123_decode (mpg, (unsigned char* ) in, in_size, reinterpret_cast<unsigned char*> (out), out_size*4, &decoded_bytes);

    ck.Samples = out;
    ck.NbSamples = decoded_bytes/sizeof(sf::Int16);

    return true;
}


Thanks for your help!  :D

2
Audio / Trouble with feeding audio stream
« on: July 11, 2009, 03:12:33 pm »
Welll, I changed it to sf::Int16* but now I have to cast it in mpg123_decode like I do in line
Code: [Select]
mpg123_decode (mpg, (unsigned char* ) in, in_size, (unsigned char*) out, out_size*2, &got_now); since mpg123_decode doesn't accept any other type than unsigned char*.
Nevertheless, the SegFault is gone but it still sounds very crappy because it stutters.

Thanks for your help

Btw: Shouldn't I change the size of the output buffer when I switch the data type?

3
Audio / Trouble with feeding audio stream
« on: July 10, 2009, 09:02:10 pm »
Quote from: "Laurent"
You should use the mpg123_format function with the MPG123_ENC_SIGNED_16 flag to setup mpg123 to output 16-bits signed integers.

Your SFML stream also needs to be Initialized with the same values that you pass to mpg123_format for channels count and samples rate.

I do both inside the constructor. I'm sorry that I didn't post it earlier. Here is the complete code of the class as well as its header. Which type of data would you suggest to use for the buffer? Would an array of sf::Int16* do better?

Thanks for your help

Edit: I am using a 64Bit system, but that shouldn't make any difference, should it?

4
Audio / Trouble with feeding audio stream
« on: July 10, 2009, 02:53:41 pm »
Quote from: "Laurent"
The format required by SFML is 16-bits signed integers. If you have an array of unsigned char it's probably different.


Well, mpg123 needs the unsigned char*s, as far as I know. Shouldn't my cast fix that problem?

Quote
And you're never deleting the memory allocated to out.

That's right, I am sorry.   :wink:

5
Audio / Trouble with feeding audio stream
« on: July 10, 2009, 02:07:11 pm »
Hello,

I try to write a program that decodes (using mpg123) and plays mp3 data from a network stream. My function for receiving and decoding is the following.
Code: [Select]
bool player::OnGetData(sf::SoundStream::Chunk& ck)

{
    size_t got_now = 0;
    for (unsigned rcb = 0; rcb < in_size; ++rcb)
    {
        char* temp = in + rcb;
        *temp = data_stream->recieve_byte();
    }

    out = new unsigned char [out_size*2];
    int ret = mpg123_decode (mpg, (unsigned char* ) in, in_size,out, out_size*2, &got_now);

    if (ret == MPG123_NEED_MORE)
        throw std::runtime_error ("Decoding error");

    ck.Samples = reinterpret_cast<sf::Int16*> (out);
    ck.NbSamples = got_now;


    return true;
}


It plays some strange noises and the I get an segmentation fault with the following backtrace
Code: [Select]
#0 0x7ff8317fa11b memcpy() (/lib/libc.so.6:??)
#1 0x7ff82dab6c6e ??() (/usr/lib/libopenal.so.1:??)
#2 0x7ff82dab6e26 alBufferData() (/usr/lib/libopenal.so.1:??)
#3 0x7ff8322a0967 sf::SoundStream::FillAndPushBuffer() (/usr/lib/libsfml-audio.so.1.4:??)
#4 0x7ff8322a0b9d sf::SoundStream::Run() (/usr/lib/libsfml-audio.so.1.4:??)
#5 0x7ff8324b5f59 sf::Thread::ThreadFunc() (/usr/lib/libsfml-system.so.1.4:??)
#6 0x7ff83135d3ba start_thread() (/lib/libpthread.so.0:??)
#7 0x7ff83185bfcd clone() (/lib/libc.so.6:??)
#8 ( 0x0000000000000000 in ??() (??:??)


I think that I'm doing something wrong when feeding the audio stream. But since I haven't got any idea what it is, I am asking you for help. My buffer are all unsigned char* arrays and I guess that they are not too small but maybe too big.
If you need more code to help me just write it.

Thanks in advance

Pages: [1]
anything