Iwanowitsch / practicesharp

Automatically exported from code.google.com/p/practicesharp
0 stars 0 forks source link

24-bit FLAC support. #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I realized the FLAC reader didn't have 24-bit support implemented in 
CopyFlacBufferToNAudioBuffer().

Couldn't you simply just add:

m_NAudioSampleBuffer[m_playbackBufferOffset++] = 
(byte)(sample);                     m_NAudioSampleBuffer[m_playbackBufferOffset++] = 
(byte)(sample >> 8);                        m_NAudioSampleBuffer[m_playbackBufferOffset++] = 
(byte)(sample >> 16);

nAudioBufferFull = m_playbackBufferOffset >= m_NAudioSampleBuffer.Length;

to the 'case 24' part of the switch statement? I did this and it play back fine.

Original issue reported on code.google.com by mathew1800 on 9 Aug 2013 at 2:48

GoogleCodeExporter commented 9 years ago
Nevermind, disregard this. After looking into it more. It seems the official 
FLAC encoder wasn't encoding the FLAC as 24 bits (even though I explicitly tell 
it to). It made a 16bit one.

Original comment by mathew1800 on 9 Aug 2013 at 3:16

GoogleCodeExporter commented 9 years ago
I have added 24-bit FLAC support (correctly this time), within the case 
statement here: 
https://code.google.com/p/practicesharp/source/browse/trunk/NAudioFLAC/Library/F
LACFileReader.cs#214

simply add:
m_NAudioSampleBuffer[m_playbackBufferOffset++] = (byte)((sample >>  0) & 0xFF);
m_NAudioSampleBuffer[m_playbackBufferOffset++] = (byte)((sample >>  8) & 0xFF);
m_NAudioSampleBuffer[m_playbackBufferOffset++] = (byte)((sample >> 16) & 0xFF);
nAudioBufferFull = m_playbackBufferOffset >= m_NAudioSampleBuffer.Length;

and it should be able to read 24-bit FLAC.

Original comment by mathew1800 on 6 Dec 2013 at 12:59

GoogleCodeExporter commented 9 years ago
Hi Mathew,
I'll be glad to add your code, but your previous comment from Aug 9, 2013 a bit 
confuses me. You wrote that the official FLAC encoder wasn't encoding the FLAC 
as 24 bits. Does it encode it now with 24 bits?

Thanks.

Original comment by yuva...@gmail.com on 6 Dec 2013 at 1:27

GoogleCodeExporter commented 9 years ago
I verified this code with this sample file, seems to work great.
http://www.pristineclassical.com/More/FLAC-24bit.html

Original comment by yuva...@gmail.com on 6 Dec 2013 at 1:32

GoogleCodeExporter commented 9 years ago
Code committed: Revision #354

Original comment by yuva...@gmail.com on 6 Dec 2013 at 1:35

GoogleCodeExporter commented 9 years ago
>You wrote that the official FLAC encoder wasn't encoding the FLAC as 24 bits.

Yeah, this was a mistake on my part. I actually don't even know why I had said 
it was the official encoder/decoder that did that. I think I actually encoded 
them wrong during testing then. Sorry about that.

Original comment by mathew1800 on 6 Dec 2013 at 3:44