- Notifications
You must be signed in to change notification settings - Fork1
Philips Semiconductors TDA8425 Hi-fi stereo audio processor emulation library
License
TexZK/TDA8425_emu
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This library aims to emulate thePhilips Semiconductors TDA8425 Hi-fi stereo audio processor.
The original goal is to contribute to the emulation of theAdLib Gold soundcard, which used such integrated circuit to add sound effects to the audiooutput, as heard in the beautiful soundtrack of theDune videogame, madespecifically for that rare sound card.
As I do not know how the actual circuits are made, I cannot emulate the chipperfectly. Instead, my goal is to simulate the overall sound, based on theshort information available.
If anybody can analyze a decapped chip, that would of course be the bestinformation, as already done for many vintage sound chips.
I am willing to get some real chips, as long as they are available forpurchase, at least for black-box comparisons with dedicated test vectors.
To use this library, just includeTDA8425_emu.c
andTDA8425_emu.h
into your project.
The engine implements the following conceptual flow:
TDA8425_Chip
memory allocation.- Call
TDA8425_Chip_Ctor()
to invalidate internal data. - Call
TDA8425_Chip_Setup()
to initialize static settings. - Call
TDA8425_Chip_Reset()
to clear emulated registers. - Call
TDA8425_Chip_Write()
for each register to inizialize. - Call
TDA8425_Chip_Start()
to start the algorithms. - Processing loop:
- Call
TDA8425_Chip_Process()
for each sample, with appropriate datatypes.
- Call
- Call
TDA8425_Chip_Stop()
to stop the algorithms. - Call
TDA8425_Chip_Dtor()
to deallocate and invalidate internal data. TDA8425_Chip
memory deallocation.
Register access timings are not emulated.
You can give a look at theTDA8425_pipe example formore details.
Here you can find some descriptions and discussions about implementationdetails.
I choseC99, because I find good old and mature C to be the best for such atiny library. C is also easier to integrate with other languages.
The code itself should be cross-platform and clean enough not to givecompilation errors or ambiguity.
Currently the library is developed and tested underWindows withMSVC++14.Of course, I will at least provide support forgcc andclang underLinux.I do not have access tomacOS, but I guess theLinux support should fit.
I chose the path of verbosity for variable declaration, to help debugging fixedpoint math and buffering. Indeed, when compiled for performance, all thosevariable declarations get optimized away easily.
It is possible to configure the floating point data type used for processing,via theTDA8425_FLOAT
preprocessor symbol. It defaults todouble
(double precision).
Please note that, contrary to common beliefs, thedouble
data type isactually very fast on machines with hardware support for it.
I think that you should switch tofloat
(single precision) only if:
- the hardware is limited to it, or
- if machine code vectorization gets faster, or
- conversion from/to buffer data to/from double precision is slower.
The input selector simply chooses which channels to feed to the internalprocessing units.
TheTDA8425_Chip_Process()
method is always provided with two stereo sources.
The library can optionally apply a high-pass filter at 10 Hz to the inputs, inorder to emulate the DC removal shown in the frequency response charts.
Theforced mono mode simply adds the two input channels together, duplicatingthe summed signal.
It looks like there is an error in the datasheet, where a switch on the rightchannel is flipped, leading to some weird path, while it is clear that it wouldsimply feed the opamp with the sum of the two channels, just like for the leftchannel:
Thelinear stereo mode does not alter the two input channels.
Thepseudo stereo mode applies two cascaded all-pass filters to the leftchannel.
All-pass filters can be configured by changing the external capacitance, as peran actual chip. The library provides the three preset values mentioned in thedatasheet.
The datasheet describes the pseudo stereo with a clear schematic.By knowning the phase diagram and the associated capacitance values, it ispossible to calculate the internal resistance values.The scriptTDA8425_pseudo.py was used in thedevelopment, to expand the expressions to calculate the biquad coefficients.It also helped in the identification of internal resistance values, whichshould be around 15 kΩ, but it looks like the plots on the datasheet are not asaccurate as those of the script.
The filter as a whole is implemented as abiquad filter.
Thespatial stereo simply adds some cross-talk between the channels.
The relationship between generic channelsa andb is the following:
Voa(t) = Via(t) + Rfa/Rc * (Via(t) - Vib(t))
whereRfa/Rc
is 52%.
A simple ideal circuit is emulated in theSPICE model:TDA8425_spatial.asc.
The datasheet plots the frequency response diagrams of two filters: thespecified one, and the mysterious (at least for me)T-filter.
Thespecified filter is a classic Baxandall-like tone control, with singlepole/zero shelving filters for both bass and treble controls.It looks like the they are centered around 300 Hz and 4500 Hz, respectively.I chosebi-linear implementation instead ofbi-quadratic for both filters,to maintain separation of concerns.They were designed with the help of theTDA8425_shelving.py Python script.
Furthermore, it looks like theT-filter has an additional second-orderfrequency response for bass control, which is factored into a dedicated biquadfilter. You can refer to theTDA8425_tfilter.py Python script for reference.
This repository provides a fully-featured example. It is a stream processor, inthat it processes sample data coming fromstandard input, elaborates it, andgenerates outputs on thestandard output.
Please refer to its own help page, by calling the canonicalTDA8425_pipe --help
, or reading it embedded inits source code.
- Ensure the following packages are installed:
sudo apt install alsa-utils audacity build-essential python3
- Enterexample folder and runmake_gcc.sh:
cd examplebash make_gcc.sh
You should find the generated executable file as
TDA8425_pipe
.Generate some noise at 192000 Hz, stereo, signed 16-bit little-endian:
python3 gen_noise.py
You should find the generated noise sample as
noise.raw
.Process noise to have full bass and treble boost, withT-filter:
./TDA8425_pipe -r 192000 -c 2 -f S16_LE -v -6 -b +15 -t +12 --t-filter< noise.raw> out.raw
- Import
out.raw
asraw data withAudacity:
- Plot the spectrum analysis:
- You can also play the audio directly with
aplay
(the\
is for commandline continuation):
./TDA8425_pipe -r 192000 -c 2 -f S16_LE -v -6 -b +15 -t +12 --t-filter< noise.raw \| aplay -c 2 -r 192000 -f S16_LE
About
Philips Semiconductors TDA8425 Hi-fi stereo audio processor emulation library