Dienstag, 18. Oktober 2016

Snakes, Neural Networks and Genetic Algorithms

Surfing around the interwebs I stumbled upon genetic algorthms, which inspired me to create my own little java applications. I won't write a lot today, instead, I made a little video to try to explain what I did. Enjoy!

- Marv

Freitag, 11. März 2016

Splitters Suck - Adventures with Optical Audio, Part III

This is part three of a multi-part series, click here to read part one or here to read part two.

After I upgraded my PC subwoofer to optical audio input, I still had a problem: My sound card has only one Toslink output. But there is remedy! Toslink splitters! Hooray!

Those things have one input and two outputs, and entirely optical (passive). However they have a major flaw: They do not work! The plug conncetions and the prism have really bad optical characteristics and too much light is absorbed. At first, I thought the fibers were to bad, but I tried short (1m) high quality cables and experienced the same problem. Even cleaning the connectors didn't make it better, I figured out that one of the outputs was stronger than the other, it barely worked, the other one didn't work at all. A piece of junk.
You can buy active splitters, but the cheapest I found were around 50 euros, way too much money. I flirted with idea of building my own optical splitter, that would mean another box that needs power and an AC adapter though.
A lot simpler is upgrading the sound card to two optical outputs! I had still some Toslink emitters around, and I didn't really need the optical input of the sound card, so why not switch an emitter for another sender? The modification is quite simple: Just desolder the receiver, hot glue the emitter at the same place upside down (you cannot use the same pins!) and wire it parallel to the existing emitter. Just an aditional 100 nF capacitor and an 8.2 k resistor is needed (according to the datasheet i found).

Quite simple, but effective. Working like a charm.
- Marv

Donnerstag, 10. März 2016

Adding S/PDIF to Analog Hardware - Adventures with Optical Audio, Part II

This is part two of a multi-part series, click here to read part one.
The solution I presented last time was working pretty well for a few years. Someday, I upgraded my PC with a Radeon 7770 graphics card. Graphics were great, the sound horrible. - The sound? What does that have to do with a new graphics card, you might ask. Well, unfortunately, either due to noise on the power/signal lines on the main board or due to electromagnetic fields, each time the graphics card processes a frame, I heard a horrible ticking on my speakers. The rate and volume changed with the framerate and the complexity of the tasks. The noise however wasn't present on the digital outputs, only the 3.5 mm jack was affected. So why not upgrade the PC speakers to toslink?

No sooner said than done! I opened up the subwoofer and looked for a nice place where I could fit in another digital to analog converter, which I had to slightly modify:
I didn't want to use the RCA jacks since these need a lot of space. A convienient connector was already present to connect the analog input PCB to the main amplifier board, I just the same one on the bottom of the converter to be able to just switch a single plug:

Since the space on the back plate is really limited, I had to mount the converter flat on the sheet metal. Therefore, the optical input had to be mounted upright:

The last thing to do, was to make a rectangular hole in the plate. I predrilled with 3 mm, then drilled an 8 mm round hole. With a file I made the hole rectangualar:

And finally, lots of hot glue to mount it securely:

And it works! Ok, to be honest, these modifications wer nothing special, but sometimes the simple way is enough. There is one problem though - my sound card has only one optical output... But that's a story for next time.
- Marv

Montag, 25. Januar 2016

Noisy Converters - Adventures with Optical Audio, Part I

I'm quite positive that everyone who once tried to transmit analog audio over a long distance encountered sound quality issues in some form. When I wanted to hook up a pair of speakers across the room to my computer, I went for a digital solution right away: TOSLINK. A simple standardized audio interface using a fiber optic cable. Its signals are identical to S/PDIF, an elektrical digital audio interface. Both TOSLINK and S/PDIF have gotten pretty common nowadays in all kinds of audio equipment such as TVs, CD players, HiFi systems and even PC sound cards. No interference, crystal clear sound, no path loss. Sounds great so far? (Pun intended)
I bought a cheap sound card for my PC with optical output, a 10 m fiber cable and a digital to analog converter.

However, whenever the converter doesn't receive an optical input, such as when the sender is turned off, it started to output ugly noise. There wasn't really much you could do against it than shutting the converter off when my PC was off. So I made a little device with a monostable circuit triggered by the optical signal that switched to power for the converter on whenever there was an active input and shut it back of when the input was inactive. The circuit was very simple, just a TOSLINK receiver, a monostable cuircuit and a transistor. Since I also had to feed to signal trough to the converter, I used the S/PDIF coax input of the DA-converter rather than to TOSLINK in order to save an optical splitter. And it was awesome in its simplicity and it also did its job.
However there is a reason why I talk in the past tense about this device and I don't have pictures of it: It isn't alive anymore because it had a major drawback: Start up clicks on my speakers. Nasty, loud clicks. And that wasn't caused by my circuit, it was the converter itself. Probably uncharged decoupling capacitors at the output. You could use some relays  at the output of the converter to disconnect the speakers until the caps are charged, but that's a third circuit and a third box. I decided to take another path in order to combine all three circuits (the power switch, the converter itself and the relays) into one - and it turned out that with the ability to disconnect the speakers from the converter output, the power switch circuit becomes obsolete.
Rather than using relays I used an analog multiplexer CD4052 and a charge pump for a negative supple voltage, since the output is AC centered around ground. An ATtiny84 does the switching for the charge pump and decides whether to turn on or off the output. A 10 k resistor is used to keep the outputs at well defined level when shut off.

Here is the code that runs on the little AVR. Basically just 50% duty-cycle high frequency pwm on the charge pump for the charge pump and an interrupt triggered "monostable" circuit with predefined time constant. I know that the same thing could also be achieved by a smaller microcontroller, the ATtiny84 was the smallest I had lying around though.

//pin definitions: 
const byte pwm = 7;  
 const byte signalin = 2;  
 const byte sel1 = 1;  
 const byte sel2 = 0;  
 const unsigned int tresholdtime = 64; // 1 ms  
 bool volatile triggered;  

 void setup(){  
  //timer0 multiply by 64  
  //millis runs 64 times as fast.  
  TCCR0B |= (1<<CS00);  
  TCCR0B &= ~((1<<CS01) | (1<<CS02));  
  PCMSK0 = (1 << PCINT2); //Enable interrupts on PCINT2 (signalin)  
  GIMSK = (1 << PCIE0);  //Enable interrupts period for PCI0 (PCINT7:0)  

 void loop(){  
  triggered = false;  
  sei(); //enable interrupts  
  delay(tresholdtime); //not nice but works  
  if (triggered){  
  } else {  

  cli(); //disable interrupts  
  triggered = true;  
I happened to be able to fit everything in the original box when I desoldered the coax jack. Even with all parts being through hole and the ICs socketed!!

And this thing got rid of all the noise. I am sure the manufacturer could have captured equivalent measures without much effort or price hike.

This is part one of a little three (or more) part series about my experiences with TOSLINK and S/PDIF.
Click here to read part two of the story.
- Marv