Comments (7)
sorry to hear that.
i searched the exception message whole of the code,but none of them has found.
i have not meet the situation for yet.
i suggest some methods to solve your problems.
- paste your exception stacks.
- do unit test with function encode and decode
- check your code ,maybe some parameters is wrong.
best regards.
from nspeex.
Hello! Thanks for your reply.
Nothing to be sorry, thanks for your time and work.
You can find the exception messages i'm referring to in the file NbDecoder.cs
"Invalid sideband mode encountered"
I'm using NSpeex in Unity Engine so i can't make unit tests.
I've already checked my code for weeks but i can't see anything wrong...
I do feed the decoder with many little segments per second and it does work flawlessy.. sometimes it decodes thousand and thousand audio segments and then something happens and boom. Exception is thrown. :)
Actually at the moment i had to switch to another encoder and solved the problem this way but if possible i would like to implement Speex because it's compression is very good.
I don't exclude something in my code can be wrong, but i need to know the exact reason for that exception so i can have a clue of the direction to look into the debugging stage.
Davide
from nspeex.
hi, by your answer, i guess the wrong encoder you has used.
the right way to use SpeexEncoder below.
SpeexEncoder(BandMode mode)
mode is decided by your samples per sec.
paste your code releted here please.
from nspeex.
I meet the same problem, when I mix up data before decode(data is still a byte[] and length doesn't change), It almost crash all the time. How can I do make it still running if I mix up data, it can sound noisy or even mute. We use speex in Android and iOS, thay wroks good in the same way. Looking forward your reply, thanks so mush!!
from nspeex.
Unfortunately i ended up using another encoder/decoder, since i was not able to avoid the random crashes with Speex.
from nspeex.
finally fixed the problem:
SpeexDecoder.cs
public int Decode(byte[] inData, int inOffset, int inCount, short[] outData, int outOffset, bool lostFrame)
{
if (decodedData.Length < outData.Length * 2)
{
// resize the decoded data buffer
decodedData = new float[outData.Length * 2];
}
if (lostFrame || inData == null)
{
decoder.Decode(null, decodedData);
for (int i = 0; i < frameSize; i++, outOffset++)
{
outData[outOffset] = ConvertToShort(decodedData[i]);
}
return frameSize;
}
bits.ReadFrom(inData, inOffset, inCount);
int samplesDecoded = 0;
while (decoder.Decode(bits, decodedData) == 0)
{
for (int i = 0; i < frameSize; i++, outOffset++)
{
outData[outOffset] = ConvertToShort(decodedData[i]);
}
samplesDecoded += frameSize;
}
return samplesDecoded;
}
to
public int Decode(byte[] inData, int inOffset, int inCount, short[] outData, int outOffset, bool lostFrame)
{
if (decodedData.Length < outData.Length * 2)
{
// resize the decoded data buffer
decodedData = new float[outData.Length * 2];
}
if (lostFrame || inData == null)
{
decoder.Decode(null, decodedData);
for (int i = 0; i < frameSize; i++, outOffset++)
{
outData[outOffset] = ConvertToShort(decodedData[i]);
}
return frameSize;
}
bits.ReadFrom(inData, inOffset, inCount);
int samplesDecoded = 0;
int result = decoder.Decode(bits, decodedData);
if (result == 0)
{
for (int i = 0; i < frameSize; i++, outOffset++)
{
outData[outOffset] = ConvertToShort(decodedData[i]);
}
samplesDecoded += frameSize;
}
return samplesDecoded;
}
NbDecoder.cs
do
{
if (bits.BitsRemaining() < 5)
return -1;
if (bits.Unpack(1) != 0)
{ /*
* Skip wideband block (for
* compatibility)
*/
// Wideband
/* Get the sub-mode that was used */
m = bits.Unpack(NSpeex.SbCodec.SB_SUBMODE_BITS);
int advance = NSpeex.SbCodec.SB_FRAME_SIZE[m];
if (advance < 0)
{
//throw new InvalidFormatException(
// "Invalid sideband mode encountered (1st sideband): "
// + m);
return -2;
}
advance -= (NSpeex.SbCodec.SB_SUBMODE_BITS + 1);
bits.Advance(advance);
if (bits.Unpack(1) != 0)
{ /*
* Skip ultra-wideband block
* (for compatibility)
*/
/* Get the sub-mode that was used */
m = bits.Unpack(NSpeex.SbCodec.SB_SUBMODE_BITS);
advance = NSpeex.SbCodec.SB_FRAME_SIZE[m];
if (advance < 0)
{
// throw new InvalidFormatException(
//"Invalid sideband mode encountered. (2nd sideband): "
// + m);
return -2;
}
advance -= (NSpeex.SbCodec.SB_SUBMODE_BITS + 1);
bits.Advance(advance);
if (bits.Unpack(1) != 0)
{ /* Sanity check */
// throw new InvalidFormatException(
//"More than two sideband layers found");
return -2;
}
}
// */
}
if (bits.BitsRemaining() < 4)
return 1;
/* Get the sub-mode that was used */
m = bits.Unpack(NSpeex.NbCodec.NB_SUBMODE_BITS);
if (m == 15)
{ /* We found a terminator */
return 1;
}
else if (m == 14)
{ /* Speex in-band request */
inband.SpeexInbandRequest(bits);
}
else if (m == 13)
{ /* User in-band request */
inband.UserInbandRequest(bits);
}
else if (m > 8)
{ /* Invalid mode */
// throw new InvalidFormatException(
//"Invalid mode encountered: " + m);
return -2;
}
} while (m > 8);
submodeID = m;
}
replace throw Exception to return -2
from nspeex.
Mate, you're a myth! Great work!
from nspeex.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nspeex.