LibADX (c)2012 Josh PH3NOM Pearson
decoder algorithm based on adx2wav (c) BERO 2001
LibADX is a library for decoding ADX audio files using the
Kallisti:OS development environment, intended for use only
on the Sega Dreamcast game console.
LibADX features full implementation of the ADX looping function.
The functions available include play, pause, stop, restart.
This library is completely free to modify and or redistribute.
LibADX is a static library, build the library with the makefile:
LibADX/LibADX/Makefile
Then build the example player:
LibADX/Makefile
The example player uses a hard-coded file name, so make sure
to include a "sample.adx" on the root of the /cd/, or modify
the source libADXplay.c to load a different file.
LibADX - A Dreamcast K:OS ADX Decoding Library
- PH3NOM
- DC Developer
- Posts: 576
- https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
- Joined: Fri Jun 18, 2010 9:29 pm
- Has thanked: 0
- Been thanked: 5 times
LibADX - A Dreamcast K:OS ADX Decoding Library
LibADX - A Dreamcast K:OS ADX Decoding Library
- Attachments
-
- LibADX.tar.gz
- LibADX v.0.1 - A Dreamcast ADX Library for KOS
- (6.64 KiB) Downloaded 165 times
Last edited by PH3NOM on Mon Feb 13, 2012 11:09 pm, edited 1 time in total.
- BlueCrab
- The Crabby Overlord
- Posts: 5658
- Joined: Mon May 27, 2002 11:31 am
- Location: Sailing the Skies of Arcadia
- Has thanked: 9 times
- Been thanked: 69 times
- Contact:
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
Just to let you know, PH3NOM, you're more than welcome to upload any Dreamcast-related stuff as an attachment on a post here, and I'd encourage you to do so. It'd probably be a good idea too, just in case the files were to get deleted from megaupload or something like that. It'd be a shame to lose stuff due to that kind of thing happening.
Also, just as a minor nit-pick, there's no : in KallistiOS or in its abbreviation.
Also, just as a minor nit-pick, there's no : in KallistiOS or in its abbreviation.
- Basil
- Insane DCEmu
- Posts: 200
- Joined: Wed Apr 09, 2008 9:04 am
- Has thanked: 13 times
- Been thanked: 0
- Contact:
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
Thank you, i read someone was asking for it.
Is there a legal way to encode to adx ?
Is there a legal way to encode to adx ?
Buy more independent Dreamcast games:
https://www.goatstore.com/Products/Sega ... elopments/
https://www.dragonbox.de/en/201-for-sega-dreamcast
https://www.goatstore.com/Products/Sega ... elopments/
https://www.dragonbox.de/en/201-for-sega-dreamcast
- mankrip
- DCEmu Ex-Mod
- Posts: 3712
- Joined: Sun Nov 04, 2001 5:12 pm
- Has thanked: 0
- Been thanked: 0
- Contact:
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
Haven't looked at it, but I guess it runs on the SH4. Did the official games use the sound processor for decoding ADX files?
- PH3NOM
- DC Developer
- Posts: 576
- Joined: Fri Jun 18, 2010 9:29 pm
- Has thanked: 0
- Been thanked: 5 times
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
FFMpeg should handle that just fine.Basil wrote:Thank you, i read someone was asking for it.
Is there a legal way to encode to adx ?
Although, looking at the source, that encoder does not support encoding loop information.
The ADX decoder consumes 1% of the Dreamcast's CPU.mankrip wrote:Haven't looked at it, but I guess it runs on the SH4. Did the official games use the sound processor for decoding ADX files?
http://www.segatech.com/technical/critools/index.html
I think the hard part with decoding ADX on the AICA would be streaming the encoded samples to the AICA.
It would be easy to upload an entire ADX to SRAM then decode it, but most ADX's will be to big to fit into SRAM, so it would need to be streamed somehow.
If anyone has some ideas on how to make this work, I would be interested to hear.
- Basil
- Insane DCEmu
- Posts: 200
- Joined: Wed Apr 09, 2008 9:04 am
- Has thanked: 13 times
- Been thanked: 0
- Contact:
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
Can you give me a tutorial ?FFMpeg should handle that just fine.
Buy more independent Dreamcast games:
https://www.goatstore.com/Products/Sega ... elopments/
https://www.dragonbox.de/en/201-for-sega-dreamcast
https://www.goatstore.com/Products/Sega ... elopments/
https://www.dragonbox.de/en/201-for-sega-dreamcast
- Neoblast
- DC Developer
- Posts: 314
- Joined: Sat Dec 01, 2007 8:51 am
- Has thanked: 3 times
- Been thanked: 1 time
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
Wow, now that is a sserious surprise.
This might end some issues with audio formats.
Hum one question, when this is loaded, does it take over the whole sound system or is it possible to load any other formats through other libs ?
This might end some issues with audio formats.
Hum one question, when this is loaded, does it take over the whole sound system or is it possible to load any other formats through other libs ?
-
- DC Developer
- Posts: 414
- Joined: Thu Aug 20, 2009 11:00 am
- Has thanked: 0
- Been thanked: 2 times
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
From a terminalBasil wrote:Can you give me a tutorial ?FFMpeg should handle that just fine.
Code: Select all
ffmpeg -i input.wav -acodec adpcm_adx output.wav
To change the audio before encoding, you can use filters in ffmpeg, or a completely different app to pipe the data to ffmpeg. Here's how you use sox to pipe data to ffmpeg
Code: Select all
sox -v 0.90 BadAppleEn.ogg -t wav -c 2 -r 22050 - | ffmpeg -i - -acodec adpcm_adx output.wav
Code: Select all
sox -v 0.90 BadAppleEn.ogg -t wav -c 1 -r 8000 -b 8 - | ffmpeg -i - -acodec adpcm_adx output.wav
EDIT 2: Couldn't find anything on saving the output of ffmpeg when encoding as ADX. I guess for now it's wav2adx or nothing.
- PH3NOM
- DC Developer
- Posts: 576
- Joined: Fri Jun 18, 2010 9:29 pm
- Has thanked: 0
- Been thanked: 5 times
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
Funny, I thought I saw it abbreviated as K:OS somewhere...BlueCrab wrote:Just to let you know, PH3NOM, you're more than welcome to upload any Dreamcast-related stuff as an attachment on a post here, and I'd encourage you to do so. It'd probably be a good idea too, just in case the files were to get deleted from megaupload or something like that. It'd be a shame to lose stuff due to that kind of thing happening.
Also, just as a minor nit-pick, there's no : in KallistiOS or in its abbreviation.
And, stupid question; Now that megaupload is in limbo, how exactly to I upload files as attachments here?
- BlueCrab
- The Crabby Overlord
- Posts: 5658
- Joined: Mon May 27, 2002 11:31 am
- Location: Sailing the Skies of Arcadia
- Has thanked: 9 times
- Been thanked: 69 times
- Contact:
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
You have to use the full "Post a reply" or "New topic" page to see the option, not the quick reply box at the bottom of the thread. Once you're on the full post editor, you should see a box labeled "Upload attachment" right underneath the Preview/Submit/Save/Cancel buttons. Pick your file, hit the add a file button, and you should be good to go.PH3NOM wrote:Funny, I thought I saw it abbreviated as K:OS somewhere...BlueCrab wrote:Just to let you know, PH3NOM, you're more than welcome to upload any Dreamcast-related stuff as an attachment on a post here, and I'd encourage you to do so. It'd probably be a good idea too, just in case the files were to get deleted from megaupload or something like that. It'd be a shame to lose stuff due to that kind of thing happening.
Also, just as a minor nit-pick, there's no : in KallistiOS or in its abbreviation.
And, stupid question; Now that megaupload is in limbo, how exactly to I upload files as attachments here?
You also should be able to upload an attachment if you just edit a post as well. The upload box should be in the same place.
If you don't see it, let me know, and I'll figure out why its not showing up.
- PH3NOM
- DC Developer
- Posts: 576
- Joined: Fri Jun 18, 2010 9:29 pm
- Has thanked: 0
- Been thanked: 5 times
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
Original post updated with attachment...Ayla wrote:Could you re-upload it plz?
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
Is anybody have tested how time (% cycle) this ADX decoding lib takes on SH4 CPU ?
- PH3NOM
- DC Developer
- Posts: 576
- Joined: Fri Jun 18, 2010 9:29 pm
- Has thanked: 0
- Been thanked: 5 times
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
Good question, I have not made any concrete benchmarks of SH4 time consumed.Newbie wrote:Is anybody have tested how time (% cycle) this ADX decoding lib takes on SH4 CPU ?
One thing I can say, is since I released that lib I have made an attempt to get the lib running on the ARM instead of the SH4.
The ARM is too slow to run the ADX decode algorithm in stereo real-time, although it was fast enough to decode mono real time. In porting the lib to the arm, I realized some deficiencies in the decoder implementation by the original author bero, that had the routine copying back and forth between temporary buffers each chunk in a stereo stream. As an attempt to optimize for the ARM, I removed the need for temporary buffer storage by adding a strided version of the chunk decoder.
The optimizations to the lib can be seen in my latest release of Dreamcast Media Center:
viewtopic.php?f=72&t=102594
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
SH4 on DC is a 200 MHZ CPU so the CPU time slice is very little.
To manage getting % of CPU time slice, we need a very accurate timer which could operate in nano (10E-9) seconds perhaps, because MHZ frequency means 10E-6 seconds period ... I am not sure.
Besides, the fact that the decoder runs on a separate thread make the thing difficult.
I tried to use the classic "timer_us_gettime64()" function by time subtraction concept.
I run the code without calling the decoder and get the execution time of the main routine then i make the same test calling the decode routine.
The result is not accurate but it seems that it takes 0 ms, probably a fraction of a ms that is not an integer ....
I am working on a object oriented version of your code to use it in my projects so i have make some modifications.
By the way, i have a thread question
I am not sure that all threads created by "thd_create" are disposed.
I could track them as they become zombie threads as their state is STATE_ZOMBIE (in thread.h).
But after ... the pointer returned by "thd_create" is not accurate to verify the dispose fact because it seems to be never null ....
Thanks for help.
To manage getting % of CPU time slice, we need a very accurate timer which could operate in nano (10E-9) seconds perhaps, because MHZ frequency means 10E-6 seconds period ... I am not sure.
Besides, the fact that the decoder runs on a separate thread make the thing difficult.
I tried to use the classic "timer_us_gettime64()" function by time subtraction concept.
I run the code without calling the decoder and get the execution time of the main routine then i make the same test calling the decode routine.
The result is not accurate but it seems that it takes 0 ms, probably a fraction of a ms that is not an integer ....
I am working on a object oriented version of your code to use it in my projects so i have make some modifications.
By the way, i have a thread question
I am not sure that all threads created by "thd_create" are disposed.
I could track them as they become zombie threads as their state is STATE_ZOMBIE (in thread.h).
But after ... the pointer returned by "thd_create" is not accurate to verify the dispose fact because it seems to be never null ....
Thanks for help.
- BlueCrab
- The Crabby Overlord
- Posts: 5658
- Joined: Mon May 27, 2002 11:31 am
- Location: Sailing the Skies of Arcadia
- Has thanked: 9 times
- Been thanked: 69 times
- Contact:
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
In the future, please make a new thread for unrelated questions. I'll let it slide and answer your question this time...Newbie wrote:By the way, i have a thread question
I am not sure that all threads created by "thd_create" are disposed.
I could track them as they become zombie threads as their state is STATE_ZOMBIE (in thread.h).
But after ... the pointer returned by "thd_create" is not accurate to verify the dispose fact because it seems to be never null ....
Thanks for help.
The pointers never get changed unless you change them. The thread code doesn't know where all your pointers are and thus can't overwrite them. Also, if you're using a relatively new version of KOS, you're going to need to make sure to either thd_join or thd_detach all your threads, otherwise they will sit around wasting memory forever (which is obviously bad).
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
I found in the last version of LibADX the code line in adx_to_pcm_stride below :
What is it useful for ?
Code: Select all
++out; // Add pointer stride to allow stereo interleave (C) PH3NOM
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
Using timer_us_gettime64(); which is in micro seconds, i found about 3 micro seconds for decoding.
But i'm not sure my method is accurate ...
But i'm not sure my method is accurate ...
- PH3NOM
- DC Developer
- Posts: 576
- Joined: Fri Jun 18, 2010 9:29 pm
- Has thanked: 0
- Been thanked: 5 times
Re: LibADX - A Dreamcast K:OS ADX Decoding Library
The reason I did that is to place the samples in their correct position in the stereo sample buffer, as stereo pcm samples are stored interleaved.Newbie wrote:I found in the last version of LibADX the code line in adx_to_pcm_stride below :
What is it useful for ?Code: Select all
++out; // Add pointer stride to allow stereo interleave (C) PH3NOM
Not only does this place the samples in the correct position, but it also removes the need to use a intermediate buffer as was being done previously:
Code: Select all
short tmpbuf[32*2];
adx_to_pcm(tmpbuf,adx_buf,prev);
adx_to_pcm(tmpbuf+32,adx_buf+ADX_Info.chunk_size,prev+1);
for(i=0;i<32;i++) {
outbuf[i*2] = tmpbuf[i];
outbuf[i*2+1] = tmpbuf[i+32];
}
Code: Select all
short *ptr = pcm_buf->buf+pcm_buf->size;
adx_to_pcm_stride(ptr,sfa_ptr,prev);
adx_to_pcm_stride(ptr+1,sfa_ptr+ADX_Info.chunk_size,prev+1);
It sounds like you are measuring time inside your main function? Would be best to measure speed within the adx library code, if you are measuring in microseconds.Newbie wrote:Using timer_us_gettime64(); which is in micro seconds, i found about 3 micro seconds for decoding.
But i'm not sure my method is accurate ...
But, it sounds like the overall performance impact of the lib is negligible.
Also, worth noting, the lib only uses integer computations, no floating point operations are used, so the Sh4's FPU is not burdened and could be executing other computations in the mean time...
My benchmarks showed LibADX to be much, much faster than using MP3... I am curious if you can compare using LibADX vs the LibMP3 that comes with KOS, using the methods you have used to record time...