Rockbox Technical Forums

Support and General Use => Recording => Topic started by: lee321987 on April 29, 2008, 05:49:29 PM

Title: Strange noises when recording to mp3
Post by: lee321987 on April 29, 2008, 05:49:29 PM
   I'm getting noise whenever I encode to mp3, regardless of the bitrate.  The noise sounds like what I hear when I encode (on my computer) at very low bitrates (e.g. 8kbps).
   I have two Sansas - c240 and c250, and I'm only getting this effect on the c250.  This noise is not present if I encode to the other available formats (AIFF, WavPack, PCM).

   Some strange things I have noticed:
--  While recording on the c240, with Gain set to 0.0 dB, during silence the peak meter rests very close to the second dot (between the left and right meters), but if I turn the Gain UP to 6.0 dB the meter rests off the screen.
--  While recording on the c250, with Gain set to 0.0 dB, the peak meter rests between the 4th and 5th dots (this is regardless of the format I'm encoding to, but as I said, playback is noiseless if I use another format).

   Any ideas?
Title: Re: Strange noises when recording to mp3
Post by: Davide-NYC on April 29, 2008, 06:47:36 PM
Can you attach an example MP3? I'm very curious to have a look/listen.
Title: Re: Strange noises when recording to mp3
Post by: lee321987 on April 29, 2008, 07:19:44 PM
   I tried, mp3 is not an allowed file extension.  I wonder if I'd be allowed to post an mp3 that I have changed the extention to .txt...?
Title: Re: Strange noises when recording to mp3
Post by: karashata on April 29, 2008, 09:43:00 PM
The forum moderators don't like people doing that, the restrictions are there to save space and bandwidth.

Upload the file to a file-sharing site and post the link here.
Title: Re: Strange noises when recording to mp3
Post by: lee321987 on April 29, 2008, 10:09:45 PM
   Thanks.
   Ok, here's the link, you'll have to turn the volume up pretty loud to hear the noise, BUT BE CAREFUL --- THE FIRST SECOND AND LAST TWO SECONDS CONTAIN MY BUTTON PRESSES WHICH ARE MUCH LOUDER THAN THE NOISE!!!

http://www.mediafire.com/?ldhcrf9ntzw
Title: Re: Strange noises when recording to mp3
Post by: Davide-NYC on April 30, 2008, 11:44:06 AM
Check out the weird DC offset. I've posted screenshots from Audacity showing the start and end of the file. Maybe this have something to do with the power section? (I don't know, just throwing ideas around) JHMikeS to the rescue?
Title: Re: Strange noises when recording to mp3
Post by: lee321987 on April 30, 2008, 04:33:40 PM
   I get the offset with both players, and in all formats (even with the OF).
   Good eye.
   Would you say my description of the noise ("like a VERY low bit rate encoding") is accurate?
   BTW this distortion is occurring even when the LCD is off.
Title: Re: Strange noises when recording to mp3
Post by: dreamlayers on May 01, 2008, 12:56:14 AM
It effectively is a low bitrate MP3.  Sure, the frame size is 160 kbps, but if you look at the file in a hex editor you'll see most bytes are FF.  When I used mp3packer  (http://www.hydrogenaudio.org/forums/index.php?showtopic=32379) on it to losslessly compress it, the resulting file is 38,845 bytes (packed from 571,024) and EncSpot says the average bitrate is 10 kbps!

Note that the noise is very faint.  It's practically a straight line on those graphs and I need to turn up the volume to hear it.  My Gmini 220 running the original firmware has the same issue.  I wonder if MP3 encoders are meant to accurately encode low volumes.  Maybe the psychoacoustic model decides it's mostly inaudible, and it devotes very few bits to it, which results in what you see and hear here.

No idea about that DC offset.  I've never seen an MP3 with a DC offset.
Title: Re: Strange noises when recording to mp3
Post by: lee321987 on May 02, 2008, 01:41:06 AM
   Ok, I just did two more recordings - a 16 kbps, and a 160 kbps, and after using mp3Packer EncSpot reports 14 and 15 kbps (respectively).  Also I compressed a 160 kbps form my c240 (the "good" one), and it turned out 134 kbps.
   So the c250 is accepting my choice of bit rate, but only encoding 16 kbps worth of data...?
   Both of my players are using the same OF and the same version of Rockbox.

   What could cause this?
Title: Re: Strange noises when recording to mp3
Post by: Llorean on May 02, 2008, 03:40:17 AM
Did you say you experience similar problems in the OF earlier?
Title: Re: Strange noises when recording to mp3
Post by: lee321987 on May 02, 2008, 04:58:51 AM
   Not the noise, just the DC offset, but the WAVs made by the OF and Rockbox do not contain this noise.
Title: Re: Strange noises when recording to mp3
Post by: dreamlayers on May 02, 2008, 08:58:39 PM
So apparently the DC offset is actually present in data coming from the ADC and not from MP3 encoding.  Perhaps the DC offset is a problem for the MP3 encoder?

Edit: Just out of curiosity I generated a file with faint white noise and a DC offset and then encoded it with LAME 3.97.  The resulting file had irregular bass pulses (which were not present in the original) but the white noise sounded otherwise okay.   I think I made my noise more intense than your noise.  Go ahead, try to encode those WAV files with LAME and see how it messes them up.
Title: Re: Strange noises when recording to mp3
Post by: lee321987 on May 03, 2008, 01:50:51 AM
   Ok, I think you're right.  Remember I said the c240 doesn't produce this noise?  I just compared (with Audacity) the size of the offset on both players.  On the c240's file the top of the (noise only) part of the wave form was just about at 0.  The top of the (noise only) part of the c250 file's wave form was at about 0.05. 

   What exactly is this number (the scale just to the left of the wave form in Audacity)?  Some variation of dB?

   Would it even be possible to program a correction for this offset into Rockbox?

   Thanks for the help guys,

Will
Title: Re: Strange noises when recording to mp3
Post by: Davide-NYC on May 03, 2008, 01:47:47 PM
   Not the noise, just the DC offset, but the WAVs made by the OF and Rockbox do not contain this noise.

Since the noise is very low DB and this does not happen with WAV files I'm going to presume it is caused by the encoder. The DC offset, on the other hand, I would presume is attributable to the hardware, since it appears with both the OF and RB.

Some questions just to clarify exactly what is going on:

Title: Re: Strange noises when recording to mp3
Post by: Llorean on May 03, 2008, 02:47:59 PM
The Rockbox MP3 encoder is, if I recall, fairly low quality. It was chosen because it's fast, rather than being tuned for quality, and should only be used if you absolutely do not have the space for higher quality file types.
Title: Re: Strange noises when recording to mp3
Post by: lee321987 on May 03, 2008, 09:02:35 PM
   Answering Davide:
 
   Yes, the offset is present on WAV's and MP3's.
   Yes, the offset is occurring on both units, but it's much stronger on the c250.
   I don't know about e2x0 units.
Title: Re: Strange noises when recording to mp3
Post by: saratoga on May 04, 2008, 11:55:24 AM
If you're encoding to mp3 anyway, lame can be told to remove the DC offset using its highpass filter option.  However, since people cannot hear a DC offset, and because DACs should filter them out, it shouldn't impact quality.
Title: Re: Strange noises when recording to mp3
Post by: lee321987 on May 04, 2008, 06:29:51 PM
   But it does seem to be the problem (at least with the Rockbox mp3 encoder).  I'm using the exact same version of Rockbox on both players (not even a different "../tools/configure" number), and the only difference I can find is that the c240 produces a much smaller offset (and doesn't produce this noise).   
   I'm not putting down Rockbox's encoder.  I think the size of the offset produced by my DAP may be a good deal over average.

   Anyway Rockbox still doubled the amount of recordings I can store internally by giving me WavPack (the OF only offered WAV), and multiplied MANY times my total capacity by allowing me to record onto the MicroSD.  Oh yeah, AND gave me 22050 Hz sample rate (OF only offered 16000 Hz).  Go Rockbox!
Title: Re: Strange noises when recording to mp3
Post by: Multiplex on May 09, 2008, 12:56:13 PM
But couldn't the offset be causing the noise?

From a PCM value of 0V to whatever the offset is may look like a sharp edge, the encoder probably can't cope with that and noise is the result of it trying to encode it.

Look at a JPG of this web page for example, the sharp transitions will cause visible noise when you zoom in.
Title: Re: Strange noises when recording to mp3
Post by: dreamlayers on May 10, 2008, 12:17:05 PM
I doubt the WAV is totally silent.  There's probably some quiet sound from the microphone and maybe some noise which is like white noise and less noticeable and less objectionable.  One could take a lossless recording, remove the offset, normalize the quiet section and see if there is some noise.

I don't think the edge is the problem, because the the problem is constant and not just at the start and end of the recording.  I think the DC offset itself is a problem.  Like I said earlier, a DC offset even messes up LAME, resulting in bass pulses.  (As someone else said, with LAME it is possible to remove that with the high pass filter.)

Title: Re: Strange noises when recording to mp3
Post by: lee321987 on May 13, 2008, 06:21:45 AM
   I did a test, a link to my results is here (http://www.mediafire.com/?t3lxl2nztzd).  In the zip is a file called "original.wav", this is a short recording of silence made using Rockbox on my c250. 
   Description of the other files:  The files with "RB_encoded" in their name were made on my c250 with Rockbox's "Open With... > mp3_encoder" command.  The files with LAME in their name were made with Audacity using LAME 3.97.  The file "offset_corrected.wav" is "original.wav" with the offset corrected by Audacity, and all mp3's with "offset_corrected" in their name were encoded from this wav.
   
   I now have no doubt that the culprit is my c250's large DC offset.
Title: Re: Strange noises when recording to mp3
Post by: Multiplex on May 23, 2008, 08:52:21 AM
   I now have no doubt that the culprit is my c250's large DC offset.
So I wonder how practical it would be to do a custom build to subtract the offset from the data comming from the ADC...
Title: Re: Strange noises when recording to mp3
Post by: Davide-NYC on May 23, 2008, 10:18:42 AM
If this noise bothers you it means you need to bite the bullet and buy a better target.
The DC offset on a recording @ 22k/16bit from a super crappy mic is not worth fretting over.
Better targets do not exhibit this behavior.
I would suggest buying an iriver h120.
If you need timestamp RTCMod it.
If you need total silence (no HD spinup) put a CFCard in it.
:)


Then again, there might be some hardware guru that can resolve this with a paperclip, some chewing gum and a piece of tinfoil. I'm not that person.

I will mention that if Rockbox keeps getting ported to crappy target with even crappier recording support (which I fully endorse, the more target supported the better) it might be a reasonable idea to try to implement an (optional) auto-DC-offset filter for recordings on targets that have the problem.
Title: Re: Strange noises when recording to mp3
Post by: AlexP on May 23, 2008, 11:04:58 AM
crappy target with even crappier recording support (which I fully endorse, the more target supported the better)

There really is no need for this.  You may not like certain targets, but plenty of people do.
Title: Re: Strange noises when recording to mp3
Post by: petur on May 23, 2008, 11:13:24 AM
there is an MP3 encoder patch in the tracker that claims to fix stuff like DC offset.
Maybe you can try it out?
Title: Re: Strange noises when recording to mp3
Post by: Davide-NYC on May 23, 2008, 11:51:40 AM
crappy target with even crappier recording support (which I fully endorse, the more target supported the better)

There really is no need for this.  You may not like certain targets, but plenty of people do.


Look, shame on  Sandisk for releasing a unit with an ADC that only does 22k and a design flaw that introduces DC offset. This is shoddy R&D and quality control on their part. DC offset with induced noise and 22k max samplerate is a deal-breaker for me and maybe OP would *NOT* have purchased the C2x0 series had they known of these flaws before hand. Caveat emptor!

My comment had nothing to do with Rockbox and everything to do with concluding to folks that are looking at the C2x0 series as a recording target (for portability probably) that the hardware is limited. For recording meetings and voice notes it'll be great. (I'm thinking about buying one as a 'loaner' device for meetings/classes I cannot attend.) But if you care about audio quality you may want to look elsewhere. (H120)

That said, the idea of implementing an optional DC-Offset filter for targets that need it might be a cool idea but it seems like it's trying to correct something that is inherently flawed.
Title: Re: Strange noises when recording to mp3
Post by: Llorean on May 23, 2008, 05:01:28 PM
The target isn't designed as a recorder though. Calling it a "crappy target" because one of its features (a VOICE recorder for use with the internal mic only) doesn't meet your requirements is overdoing it.

The player itself handles MP3 playback quite fine, and it's very tiny and light. It has MicroSD allowing for practically unlimited storage/variety despite its tiny size. And to boot it has FM radio in case you'd like to sample local culture. His point was that calling it a crappy target over one minor feature that wasn't even an intended selling point of the hardware is somewhat ridiculous. It's not sold as a real recorder, it's sold as having voice recording out of the mic, and even natively records to a VERY low quality file. I don't see anything that suggests that they want to convince users that it's a high quality, or even mid-quality, recorder. It's not a recording target. It's just a player that has some recording features.

Improving flawed hardware is kinda what we do here. Or would you argue against us trying to fix the remote ticking problem in the H120?
Title: Re: Strange noises when recording to mp3
Post by: lee321987 on June 04, 2008, 11:50:55 PM
  Good news.  I just upgraded to r17687, and now when recording directly to mp3 the noise (that I started this subject for) is gone, AND the DC offset appears to be completely gone too (for mp3s). 
  If I first record a wav, and then (on my player) use "Open with..." > "mp3_encoder", the offset IS present, but still - not the noise!)
  I assume the fix was due to the changes at r17679 (http://svn.rockbox.org/viewvc.cgi?view=rev;revision=17679). 

  Thanks again to the Rockbox team.