Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Welcome to the Rockbox Technical Forums!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Adding time delay to left channel on sound output
« previous next »
  • Print
Pages: [1] 2

Author Topic: Adding time delay to left channel on sound output  (Read 9464 times)

Offline s3t

  • Member
  • *
  • Posts: 9
Adding time delay to left channel on sound output
« on: March 14, 2010, 11:25:30 AM »
Hi all,

Could you please suggest me where do i put a piece of code to add a delay to left channel?
It should be just a few ms delay - i need it in car audio installation where i use iRiver ihp-120 as main audio source.
The delay is needed to time align left and right channels in car environment.
The distance to left and right speakers in car is not symmetrical, therefore the sound produced by speakers comes with different delay to the listener, so the delays has to be "aligned" to make listener (me :) ) happy.

The way i think it should be implemented is using a FIFO buffer (array) with pointers (indexes) for reading and writing, which will store the audio data.

Another option is to mess with existing audio buffer, and adjusting it's reading addresses for different channels:
Say we are at #900 position of buffer, then the right channel reads #900, and the left -  #800 (#900-100) (100 samples difference).


I'm unfamiliar with the internals of RockBox firmware, so i ask Your advice which is the easiest way to do this?

Thank you for the best firmware ever for the mp3! It really makes the mp3 players shine! :) I love it so much i decided to put it in car instead of head unit :)
Logged

Offline Recording Guy

  • Member
  • *
  • Posts: 33
Re: Adding time delay to left channel on sound output
« Reply #1 on: March 23, 2010, 08:04:22 PM »
I would have thought a Digital Delay Pedal might be the best way to go about your task,
you could split the lead and run the left channel through the delay, then you could "fine tune"
the ms delay that you are after.

Something like this maybe :

http://www.gear4music.com/Guitar-and-Bass/Behringer-DD400-Digital-Delay-Pedal/4I1

Have you tried panning your amp to get a stronger left signal towards the drivers side?

Just a couple of thoughts to an unusual conundrum  ;)
Logged

Offline perfectdrug

  • Artist
  • Member
  • *
  • Posts: 103
Re: Adding time delay to left channel on sound output
« Reply #2 on: March 23, 2010, 09:04:35 PM »
I thought that is what Balance is for.
Logged
uʍop ǝpısdn < sbuıʇʇǝs pɔ1 < ʎɐ1dsıp < sbuıʇʇǝs 1ɐɹǝuǝb

Offline saratoga

  • Developer
  • Member
  • *
  • Posts: 9148
Re: Adding time delay to left channel on sound output
« Reply #3 on: March 23, 2010, 09:20:25 PM »
I think balance only adjusts volume, not phase delay.
Logged

Offline s3t

  • Member
  • *
  • Posts: 9
Re: Adding time delay to left channel on sound output
« Reply #4 on: March 24, 2010, 04:34:04 PM »
The pedal is nice as long as it stays in digital domain of signal path which is not the case here... Yet it's nice to know such product exists.

I choose the old iriver player for it's ability to give spdif/toslink output, which i use to feed some diy DAC.

I want to keep away from unnecessary analog-digital-analog conversions, which, probably, will kill the quality of sound.

I'm trying to mimic the sophisticated head units which do "time alignment" feature...

Logged

Offline Llorean

  • Member
  • *
  • Posts: 12931
Re: Adding time delay to left channel on sound output
« Reply #5 on: March 24, 2010, 04:59:14 PM »
Does your car have 100% isolation from outside noise?

It seems like you're going through an awful lot of effort to "improve" sound in a situation where background noise will overwhelm and of the incredibly minor improvements you're going to get from avoiding one extra D->A conversion (assuming decent things are doing the conversion)  or trying to adjust the audio delay a few milliseconds.
Logged

Offline ew

  • Member
  • *
  • Posts: 52
Re: Adding time delay to left channel on sound output
« Reply #6 on: March 24, 2010, 05:13:29 PM »
Can you really tell the difference?  Sound travels at 1125 ft/sec.  Assuming that the right speaker is 4 ft more than the left one, you are trying to insert a delay of a whopping .0036 seconds!

Do you have front and rear speakers in your car?  Does the back sound out of phase with the front?

Perhaps I am just not getting something here.
Logged

Offline saratoga

  • Developer
  • Member
  • *
  • Posts: 9148
Re: Adding time delay to left channel on sound output
« Reply #7 on: March 24, 2010, 05:28:58 PM »
Quote from: ew on March 24, 2010, 05:13:29 PM
Can you really tell the difference?  Sound travels at 1125 ft/sec.  Assuming that the right speaker is 4 ft more than the left one, you are trying to insert a delay of a whopping .0036 seconds!

Thats actually a pretty large difference, and you can pretty easily hear it.  Thats a large part of how your ears directional hearing works.


http://en.wikipedia.org/wiki/Interaural_time_difference
Logged

Offline yapper

  • Rockbox Expert
  • Member
  • *
  • Posts: 794
Re: Adding time delay to left channel on sound output
« Reply #8 on: March 24, 2010, 05:32:46 PM »
Obviously any adjustment you make to suit the driver will have an opposite effect on the passenger's experience.
Logged
G2 iPod 20GB / Sansa c240 v1 + 2GB microSD / Sansa c250 v1 / Sansa e250 v1 + 8GB microSDHC / Sansa Fuze v2 + 32GB microSDHC

Offline s3t

  • Member
  • *
  • Posts: 9
Re: Adding time delay to left channel on sound output
« Reply #9 on: March 25, 2010, 04:51:59 AM »
Llorean, my isolation is quite mediocre, so i really doubt whether its worthwhile to build "hi-end" system in car environment...
In the other hand, the iriver's analog output is not that good, and the idea of player>spdif>dac>amplifier signal path is really great for in-car use - there is no noise coming from long RCA cables that run across the car, nor hum of ground mismatches between head unit and amplifier grounds.

The alteration of RockBox's source code is in my opinion the easiest way to get the feature of time alignment, as it should be simple to implement.
Another way of doing this is to build hardware device that will take i2s, split it into 2 channels, and run one of channels thru FIFO buffer. But it is way too much hassle for the task.

ew,
The difference is whether you feel like you are standing on the left to the singer, or in front of him.

yapper, both driver and passenger can't be happy in the car the same time...
Mostly i drive alone, so there are no passengers. And if there are some - they rarely are audiophiles. And even if they actually are audiophiles - i could be able to turn off the time correction thru the menu.
Logged

Offline s3t

  • Member
  • *
  • Posts: 9
Re: Adding time delay to left channel on sound output
« Reply #10 on: May 23, 2011, 06:30:10 PM »
Please please please, guys, help me out with this - just a name of file i should look into.
The last time i tried to investigate the data flow, it turned out there is DMA thing, which prevented me from inserting the delay near the codec driver (the CPU feeds the codec using it's internal routines for DMA managing?)

Well, another option is to go to EQ section, and check out how the IIR filters are applied. All in all there is 100% chance of getting direct access to data stream.



UPD: dsp.c is the file, and int dsp_process(...) is the process.
t2[0..1] have both channels.
and now... i need to create global array for 64 samples, hooray!
« Last Edit: May 23, 2011, 07:43:20 PM by s3t »
Logged

Offline s3t

  • Member
  • *
  • Posts: 9
Re: Adding time delay to left channel on sound output
« Reply #11 on: May 24, 2011, 07:40:25 PM »
And, the end of story: mission accomplished, i've got the delay.

It was really easy after i've found the dsp.c.
Made circulating "log" buffer of 128 samples in int32_t array, and some "if" statement for calculating the playback position.

I'm unable to make patch/contribute, as i believe my source already violated a couple of rules, i've bricked the "crossfeed" function, i don't have settings page for the delay (i use crossfeed's instead), and... my current source is already modified for SW volume.
Logged

Offline Recording Guy

  • Member
  • *
  • Posts: 33
Re: Adding time delay to left channel on sound output
« Reply #12 on: May 25, 2011, 05:34:36 PM »
Well done!  ;D
Logged

Offline s3t

  • Member
  • *
  • Posts: 9
Re: Adding time delay to left channel on sound output
« Reply #13 on: May 26, 2011, 06:11:38 AM »
Looks like my ideas gone wild.
I want to try digital room correction in there, down to some 500-1000hz range (keeping FIR filter sequence short).
n^2 multiplifications, where n=FIR length.
n=Fs/Fo
Seems a lot of multiplifications there...
For Fo=500:
Fs:   44100
Fo:   500
Taps:   88.2
Multiplifications:   7779.24

1000hz
Fs:   44100
Fo:   1000
Taps:   44.1
Multiplifications:   1944.81

Going over >1kHz doesn't makes sense...
Well, probably i should leave the idea out.
Or... maybe... I'll throw a "while" loop in there, that will do some multiplication just to check the performance.


Probably won't work, as i need ~2000 multiplications per 44100 cycle. It translates into minimum of 44100 *2000 multiplications per second = minimum 88mhz as long as single multiplication takes 1 clock cycle.


Another idea... there is both TosLink and analog outputs on the player. I have checked the CODEC datasheet and it doesn't support TosLink = therefore, the TosLink transmitter is connected to the CPU directly = it should have separate I2S bus, and be able to produce sounds different from the CODEC.
What i'm trying to say is i could get 4 separate channels out of iRiver! All i need to squeeze there is additional delay to make the subwoofer and front stage produce time-coherent waves at listening position... Wow!
« Last Edit: May 26, 2011, 10:53:41 AM by s3t »
Logged

Offline fcporto

  • Member
  • *
  • Posts: 3
Re: Adding time delay to left channel on sound output
« Reply #14 on: June 02, 2011, 07:50:06 PM »
hi st3 !
Great work!
I am not a developer, just a simple RockBox user. I was eagerly waiting for someone to develop this time delay tool! I too love to hear music in my car and imaging is always misplaced in an asymmetrical listening position like this (unless you own a McLaren F1...). Time delay is a very useful feature to correct this and it is only available in top head units or sound processors. Newer cars do not allow to change the stereo, so we are left with the (usually expensive) option of adding a digital sound processor. The idea of bringing it to RockBox is great, and I just wonder if it will be incorporated in future versions of this wonderful open source software (in my case, I'm using a 5th gen iPod).
Thanks !
Logged

  • Print
Pages: [1] 2
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Adding time delay to left channel on sound output
 

  • SMF 2.0.18 | SMF © 2021, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.038 seconds with 17 queries.