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 - s.baus

Pages: 1 2 [3]
31
DotNet / Re: DLL issues again
« on: July 09, 2014, 08:12:27 am »
Hey, I'm currently also working on a Linux port (since I also use mono) and had the same problem: I searched the net a bit and found this: https://stackoverflow.com/questions/23448259/sfml-net-cant-locate-native-library-on-linux
The comment
Quote
Wait, looks like i found the missing link... libcsfml != libsfml
seems to do the trick. I corrected the libcsfml to libsfml and came a bit further (I get an exception, but not the dllnotfoundexception). Try this ;).

32
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: July 09, 2014, 07:43:12 am »
I tried a bit around, and you know what works? Setting the buffer size to 2048 (just a bit trying):

protected override bool OnGetData(out short[] samples)
        {
            float[] normalizedaudiodata = new float[2048];
            int readSamples = mp3file.ReadSamples(normalizedaudiodata, 0, normalizedaudiodata.Length);
            short[] pcmaudiodata;
            if (readSamples > 0)
            {
                pcmaudiodata = new short[readSamples]; // converted data
                for (int i = 0; i < readSamples; i++)
                {
                    // clip the data
                    if (normalizedaudiodata[i] > 1.0f)
                    {
                        normalizedaudiodata[i] = 1.0f;
                    }
                    else
                    {
                        if (normalizedaudiodata[i] < -1.0f)
                        {
                            normalizedaudiodata[i] = -1.0f;
                        }
                    }
                    // convert to pcm data
                    pcmaudiodata[i] = (short)(normalizedaudiodata[i] * short.MaxValue);
                }
                samples = pcmaudiodata;
                return true;
            }
            else
            {
                samples = null;
                return false;
            }
        }

But I remember having read, that a too large buffer could decrease performance and therefore should be as little as possible. Do you have an idea, why it works with large buffer?

33
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: July 08, 2014, 09:09:45 am »
Can you show the other functions of your class?
No Problem, here is the whole class ;):

public class Mp3StreamSFML : SoundStream
    {
        private MpegFile mp3file;
        private int currentBufferSize;
        private short[] currentBuffer;

        public Mp3StreamSFML(String _filename)
        {
            mp3file = new MpegFile(_filename);
            Initialize((uint)mp3file.Channels, (uint)mp3file.SampleRate);
            currentBufferSize = 0;
            currentBuffer = new short[currentBufferSize];
        }

        #region implemented abstract members of SoundStream

        protected override bool OnGetData(out short[] samples)
        {
            float[] normalizedaudiodata = new float[128];
            int readSamples = mp3file.ReadSamples(normalizedaudiodata, 0, normalizedaudiodata.Length);
            short[] pcmaudiodata;
            if (readSamples > 0)
            {
                pcmaudiodata = new short[readSamples]; // converted data
                for (int i = 0; i < readSamples; i++)
                {
                    // clip the data
                    if (normalizedaudiodata[i] > 1.0f)
                    {
                        normalizedaudiodata[i] = 1.0f;
                    }
                    else
                    {
                        if (normalizedaudiodata[i] < -1.0f)
                        {
                            normalizedaudiodata[i] = -1.0f;
                        }
                    }
                    // convert to pcm data
                    pcmaudiodata[i] = (short)(normalizedaudiodata[i] * short.MaxValue);
                }
                samples = pcmaudiodata;
                return true;
            }
            else
            {
                samples = null;
                return false;
            }
        }

        protected override void OnSeek(TimeSpan timeOffset)
        {
            //TODO
            //mp3file.Position = 0;
            //mp3file.Position = (long)timeOffset.TotalSeconds;
        }

        #endregion
    }

34
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: July 08, 2014, 08:11:38 am »
new short[normalizedaudiodata.Length]

You need to use the actual number of samples that were read, not just the maximum length of your buffer.

Thanks for your help, I modified the code this way:

protected override bool OnGetData(out short[] samples)
        {
            float[] normalizedaudiodata = new float[128];
            int readSamples = mp3file.ReadSamples(normalizedaudiodata, 0, normalizedaudiodata.Length);
            short[] pcmaudiodata;
            if (readSamples > 0)
            {
                pcmaudiodata = new short[readSamples]; // converted data
                for (int i = 0; i < readSamples; i++)
                {
                    // clip the data
                    if (normalizedaudiodata[i] > 1.0f)
                    {
                        normalizedaudiodata[i] = 1.0f;
                    }
                    else
                    {
                        if (normalizedaudiodata[i] < -1.0f)
                        {
                            normalizedaudiodata[i] = -1.0f;
                        }
                    }
                    // convert to pcm data
                    pcmaudiodata[i] = (short)(normalizedaudiodata[i] * short.MaxValue);
                }
                samples = pcmaudiodata;
                return true;
            }
            else
            {
                samples = null;
                return false;
            }
        }

I'm hearing nothing, Windows Sound sees my application wants to start audio output (I'm using windows 7) but there is no peak and nothing to hear. What I'm doing wrong?

35
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: July 07, 2014, 04:02:07 pm »
Hello, thanks for your help. I now optimized the code to the following:

protected override bool OnGetData(out short[] samples)
        {
            float[] normalizedaudiodata = new float[128];
            int readSamples = mp3file.ReadSamples(normalizedaudiodata, 0, normalizedaudiodata.Length);
            short[] pcmaudiodata;
            if (readSamples > 0)
            {
                pcmaudiodata = new short[normalizedaudiodata.Length]; // converted data
                for (int i = 0; i < normalizedaudiodata.Length; i++)
                {
                    // clip the data
                    if (normalizedaudiodata [i] > 1.0f)
                    {
                        normalizedaudiodata [i] = 1.0f;
                    }
                    else
                    {
                        if (normalizedaudiodata [i] < -1.0f)
                        {
                            normalizedaudiodata [i] = -1.0f;
                        }
                    }
                    // convert to pcm data
                    pcmaudiodata[i] = (short)(normalizedaudiodata[i] * short.MaxValue);
                }
                samples = pcmaudiodata;
                return true;
            }
            else
            {
                samples = null;
                return false;
            }
        }

But this also just doesn't work, I hear nothing :(. What can I do now?

36
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: July 07, 2014, 08:42:06 am »
Thank you for your great help. I use this code, but now I hear nothing (turned the volume up to 100 ;)).:

protected override bool OnGetData(out short[] samples)
        {
            if (currentBufferSize <= mp3file.Position)
            {
                byte[] buffer = new byte[512];
                int readSamples = mp3file.ReadSamples(buffer, 0, buffer.Length);
                if (readSamples > 0)
                {
                    float[] normalizedaudiodata = new float[readSamples / 4];// { 1.0f, -1.0f, 0.5f, -0.5f, 2.0f, -2.0f }; // normalized data from decoder
                    Buffer.BlockCopy(buffer, 0, normalizedaudiodata, 0, buffer.Length);
                    short[] pcmaudiodata = new short[normalizedaudiodata.Length]; // converted data
                    for (int i = 0; i < normalizedaudiodata.Length; i++)
                    {
                        // clip the data
                        if (normalizedaudiodata [i] > 1.0f)
                        {
                            normalizedaudiodata [i] = 1.0f;
                        }
                        else
                        {
                            if (normalizedaudiodata [i] < -1.0f)
                            {
                                normalizedaudiodata [i] = -1.0f;
                            }
                        }
                        // convert to pcm data
                        pcmaudiodata[i] = (short)(normalizedaudiodata[i] * short.MaxValue);
                    }
                    // do whatever you want with the converted data
                    int startIndex = currentBuffer.Length;
                    Array.Resize(ref currentBuffer, currentBuffer.Length + pcmaudiodata.Length);
                    for (int i = startIndex; i < currentBuffer.Length; i++)
                    {
                        currentBuffer [i] = pcmaudiodata [i - startIndex];
                    }

                    //Array.Resize(ref currentBuffer, currentBuffer.Length + buffer.Length);
                    //Buffer.BlockCopy(buffer, 0, currentBuffer, currentBufferSize, readSamples);
//                    for (int i = 0; i < (buffer.Length / 4); i++)
//                    {
//                        currentBuffer[currentBufferSize + (i/4)] = (short)(BitConverter.ToSingle(buffer, i * 4) * 32767);
//                    }
                }
                samples = currentBuffer;
                return true;
            }
            else
            {
                samples = currentBuffer;
                return false;
            }
        }


What I am doing wrong? How can I find an error?

37
DotNet / Re: DLL issues again
« on: July 05, 2014, 12:59:20 pm »
Hello,

I had similar problems on linux, but can't remember what I actually did. Are you sure, that the file "libcsfml-graphics.so.2" exists on /usr? Is it only a link or a real file?

Hope this helps a bit
Sven

38
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: July 05, 2014, 12:55:58 pm »
Thank you again, here the answer :):

Quote
It's nominally [-1.0 ... +1.0], but you should expect some out of range values with "loud" sounds. Deal with them like you would any other out-of-range samples (usually clipping, but an audio compressor will also do the trick if set up correctly).

Do we need more information? :)

39
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: July 03, 2014, 07:36:42 pm »
Sorry for answering so late, but I had to get the information from NLayer developer. Here is the answer:

Quote
It returns 32-bit little-endian floats. You can copy it to a float[] buffer (use Buffer.BlockCopy), then do your processing from there.

The samples are started in channel-interleaved format (just like WAV files).

Do you have a hint for me, how to do the work from float buffer to short buffer? Thanks in advance ;).

40
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: June 11, 2014, 02:46:48 pm »
Working with this code, I get only some "clicking" sound:

protected override bool OnGetData(out short[] samples)
        {
            if (currentBufferSize <= mp3file.Position)
            {
                byte[] buffer = new byte[512];
                int readSamples = mp3file.ReadSamples(buffer, 0, buffer.Length);
                if (readSamples > 0)
                {
                    Array.Resize(ref currentBuffer, currentBuffer.Length + buffer.Length);
                    //Buffer.BlockCopy(buffer, 0, currentBuffer, currentBufferSize, readSamples);
                    for (int i = 0; i < (buffer.Length / 4); i++)
                    {
                        currentBuffer[currentBufferSize + (i/4)] = (short)(BitConverter.ToSingle(buffer, i * 4) * 32767);
                    }
                }
                samples = currentBuffer;
                return true;
            }
            else
            {
                samples = currentBuffer;
                return false;
            }
        }

How can I check, what soundformat is read by nlayer?

41
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: June 11, 2014, 02:07:57 pm »
I tried now this (from http://www.codeproject.com/Articles/501521/How-to-convert-between-most-audio-formats-in-NET), but this also doesn't work:

        protected override bool OnGetData(out short[] samples)
        {
            if (currentBufferSize <= mp3file.Position)
            {
                byte[] buffer = new byte[512];
                int readSamples = mp3file.ReadSamples(buffer, 0, buffer.Length);
                if (readSamples > 0)
                {
                    Array.Resize(ref currentBuffer, currentBuffer.Length + buffer.Length);
                    //Buffer.BlockCopy(buffer, 0, currentBuffer, currentBufferSize, readSamples);
                    int destOffset = currentBufferSize;
                    for (int sample = 0; sample < buffer.Length; sample++)
                    {
                        // adjust volume
                        float sample32 = buffer[sample];
                        // clip
                        if (sample32 > 1.0f)
                            sample32 = 1.0f;
                        if (sample32 < -1.0f)
                            sample32 = -1.0f;
                        currentBuffer[destOffset++] = (short)(sample32 * 32767);
                    }
                    currentBufferSize = currentBuffer.Length;
                }
                samples = currentBuffer;
                return true;
            }
            else
            {
                samples = currentBuffer;
                return false;
            }
        }

42
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: June 11, 2014, 11:08:30 am »
Ok, thanks again for your information. I'm not familiar with all this audio stuff, so I'm asking a bit dumb, you might think.
You said, this is a 32-bits-float sample, so I would say 4 elements of the read byte array represent 1 sample, correct? This 1 sample would take 2 elements in the short array passed to sfml,correct?

43
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: June 11, 2014, 10:24:22 am »
Thanks for your help, I changed the Method this way:

protected override bool OnGetData(out short[] samples)
        {
            if (currentBufferSize <= mp3file.Position)
            {
                byte[] buffer = new byte[512];
                int readSamples = mp3file.ReadSamples(buffer, 0, buffer.Length);
                if (readSamples > 0)
                {
                    Array.Resize(ref currentBuffer, currentBuffer.Length + (readSamples / 2));
                    Buffer.BlockCopy(buffer, 0, currentBuffer, currentBufferSize, readSamples);
                    currentBufferSize = currentBuffer.Length;
                }
                samples = currentBuffer;
                return true;
            }
            else
            {
                samples = currentBuffer;
                return false;
            }
        }

Also, I do not believe simply converting the array as you are doing is the proper way to convert audio data from a byte array to a short array (PCM) that SFML requires.

I have read in the internet, that this would be the safest way of converting byte[] to short[]. How should it be done?

44
DotNet / Re: NLayer MpegFile to SFML.Net SoundStream
« on: June 10, 2014, 08:46:02 am »
No one any ideas? ;)

45
DotNet / NLayer MpegFile to SFML.Net SoundStream
« on: June 07, 2014, 12:28:53 pm »
Hello everybody,

I'm currently working on SFML.Net to expand with mp3 support. Therefore I wrote a Stream class which uses NLayer MpegFile to decode the mp3.

   
public class Mp3StreamSFML : SoundStream
    {
        private MpegFile mp3file;
        private int currentBufferSize;
        private short[] currentBuffer;

        public Mp3StreamSFML(String _filename)
        {
            mp3file = new MpegFile(_filename);
            Initialize((uint)mp3file.Channels, (uint)mp3file.SampleRate);
            currentBufferSize = 0;
            currentBuffer = new short[currentBufferSize];
        }

        #region implemented abstract members of SoundStream

        protected override bool OnGetData(out short[] samples)
        {
            if (currentBufferSize <= mp3file.Position)
            {
                byte[] buffer = new byte[512];
                if (mp3file.ReadSamples(buffer, 0, buffer.Length) > 0)
                {
                    Array.Resize(ref currentBuffer, currentBuffer.Length + (buffer.Length / 2));
                    Buffer.BlockCopy(buffer, 0, currentBuffer, currentBufferSize, buffer.Length);
                    currentBufferSize = currentBuffer.Length;
                }
                samples = currentBuffer;
                return true;
            }
            else
            {
                samples = currentBuffer;
                return false;
            }
        }

        protected override void OnSeek(TimeSpan timeOffset)
        {
            mp3file.Position = (long)timeOffset.TotalSeconds;
        }

        #endregion
    }

I use it this way:

                   
try
                    {
                        stream = new Mp3StreamSFML(this.objProgram.getObjCuesheet().getAudiofilePath(true));
                        stream.Play();
                        log.debug("samplerate = " + stream.SampleRate);
                    }
                    catch(Exception ex)
                    {
                        log.fatal(ex.ToString());
                    }

Unfortunately, there is not the correct sound played, its just "juttering" and sound really weird. What I'm doing wrong? Seems like a problem between the 2 Frameworks.

NLayer:https://nlayer.codeplex.com/

Thanks for your help ;).
Sven

Pages: 1 2 [3]
anything