Log in

View Full Version : Capturing cable box audio through toslink


ENunn
10th August 2021, 03:50
I'm trying to capture some audio through the Toslink port on my cable box. I usually capture through AmarecTV through my Elgato HD60S. Worked fine for me for years but I want to try recording through Toslink due to the possibility of recording 5.1 (HD60S doesn't support that).

I have the Sound Blaster X-Fi Xtreme Audio. A long time ago I tried recording the audio at 24bit 48khz through Audacity but decoding it was too confusing. I still don't know how to do it. I want to be able to capture video while recording the audio stream through Toslink without worrying about decoding through software and syncing everything up. Is there a way I can do it?

tebasuna51
10th August 2021, 08:18
The Sound Blaster X-Fi Xtreme Audio have a optical Toslink input port, but I don't know if can store in a file that input.

If it can please upload a sample file to see your problem with decoding and sync.

ENunn
10th August 2021, 22:13
If it can please upload a sample file to see your problem with decoding and sync.

here you go!

can't attach them directly.
https://mega.nz/file/Ss9DXIrC#yhyH1s5igKRzlQwTgAR-ryttAzV_W_TzJ1Dz0nESUIw
https://mega.nz/file/S41lCABI#pIgrkvmV-thds0Pp4WhoBQKRRJRBW5r-W8IWgRO1VSI

recorded both at 48k/24bit with audacity

tebasuna51
11th August 2021, 10:17
Sorry but I can't recover the audio of these files.

Ignoring the wrong wav header included by Audacity the raw data can't be recognized like PCM (with any channels, bitdepth or samplerate) or AC3 (without valid AC3 headers).

Maybe some user with Sound Blaster X-Fi Xtreme experience can help you, I can't do it.

ENunn
13th August 2021, 07:47
Sorry but I can't recover the audio of these files.

Ignoring the wrong wav header included by Audacity the raw data can't be recognized like PCM (with any channels, bitdepth or samplerate) or AC3 (without valid AC3 headers).

Maybe some user with Sound Blaster X-Fi Xtreme experience can help you, I can't do it.

Thanks for trying! I remember successfully getting the headers recorded once or twice, but I don't remember where the files are.

If anyone has any other ideas, I'd appreciate it. I haven't minded recording 2 channels for a while, although I want to see if I can record 5.1.

pandy
14th August 2021, 20:03
If anyone has any other ideas, I'd appreciate it. I haven't minded recording 2 channels for a while, although I want to see if I can record 5.1.

"Brute force" approach: https://github.com/pfrench42/saleae_spdif
+ 9$ Comidox USB Logic Analyzer 24MHz 8CH - should work for every type of audio available on TOS-link (you may need additionally TOS-Link receiver)

ENunn
26th August 2021, 23:44
"Brute force" approach: https://github.com/pfrench42/saleae_spdif
+ 9$ Comidox USB Logic Analyzer 24MHz 8CH - should work for every type of audio available on TOS-link (you may need additionally TOS-Link receiver)

Just now seeing this. I'll give this a shot once I get the analyzer, but this looks wayyyy too confusing to set up. Where would I plug the toslink cable? Can I not use my Sound Blaster? Is there anything that just works without any additional hardware?

j7n
27th August 2021, 19:15
You need to record in 16-bit in bit-perfect mode. I recall that Sound Blaster could be switched into gaming/media/creator modes. Your sample has noise-shaped dither added, which makes conversion harder.

Here is your sample rounded to 16-bit with Sound Forge and converted with BSCONVERT.EXE from AC3Filter tools.

http://j7n.sytes.net/temp/testdolby-bs.ac3

ENunn
29th August 2021, 00:16
You need to record in 16-bit in bit-perfect mode. I recall that Sound Blaster could be switched into gaming/media/creator modes.

Where do I find that? I can't seem to find anything about a bit-perfect mode in the control panel. Also, are you sure it's 16-bit and not 24-bit? I've looked on other sites and they said record at 24. I tried recording with Audacity with the card set to 16-bit, it just recorded in 24-bit for some reason.

Your sample has noise-shaped dither added, which makes conversion harder.

Is that part of the signal? The program I was recording has heavy background noise because my local station can't seem to use a good compressor for some reason.

j7n
29th August 2021, 08:28
The signal source outputs compressed data. Sample values have to be transmitted exactly, or the data can't be recovered at all. Dither was added during the capture process on the computer by the soundcard driver, Windows or Audacity to be helpful with regular uncompressed sound. See if you can switch dither off in the preferences of Audacity, and if that makes a difference. Save it as 16-bit, then process with bsconvert.exe to trim out silence and S/PDIF headers. Maybe new Xi-Fi cards on new Windows no longer have that panel. I used SB Xi-Fi with a breakout box a long time ago.

Compressed AC-3 is at most 640 kbit/s. It is transmitted in the top 16 bits for robustness. Capturing at 24-bit is a valid suggestion because this allows to remove dither if it can't be avoided in the first place. The silent gaps (http://j7n.sytes.net/temp/spdifdither.png) between AC-3 frames have to be exactly 00, and will be preceded by byte sequence 72 F8 1F 4E.

Seems like AC3Filter is gone from the web. I uploaded bsconvert.zip (http://j7n.sytes.net/temp/bsconvert.zip)

ENunn
29th August 2021, 23:54
Dither is off in Audacity. I was able to set my device and Audacity to record in 16-bit. Ran it through bsconvert and it's still not right. Don't know what's up. Same thing with recording in 24-bit. Very odd. Don't know what I'm doing wrong.

j7n
30th August 2021, 00:23
Record the same way as you did testtoslink.wav.

Then use SoX command-line tool, which is free, to convert to 16-bit. With my version of SoX I get valid AC-3 data. -D disables dither. I can't advise about Audacity because I don't use it.

sox -D testtoslink.wav -b 16 testtoslink-sox.wav (http://j7n.sytes.net/temp/testtoslink-sox.wav)
bsconvert testtoslink-sox.wav testtoslink-bs.ac3 (http://j7n.sytes.net/temp/testtoslink-bs.ac3)

ENunn
30th August 2021, 09:45
What software do you use to capture the audio? I tried the exact setup as testtoslink.wav in Audacity, most of the time I'm getting no audio at all when trying to convert it, unless Dolby Digital is somehow ruining it.

j7n
30th August 2021, 14:28
I happen to use E-MU 0404 with Sound Forge or Reaper in ASIO mode. The driver is written to largely bypass Windows, dither, resampling and volume control. I can't see what is different in your setup now, only that the two provided samples were perfectly recoverable. When you say no audio, do you get silence recorded instead of the chopping noise of Dolby data?

I just found out that MPC-HC is able to play the "inflated" 16-bit PCM/SPDIF data directly.

ENunn
30th August 2021, 21:23
I happen to use E-MU 0404 with Sound Forge or Reaper in ASIO mode. The driver is written to largely bypass Windows, dither, resampling and volume control.

Might need to pick one of those up if this doesn't work out :P

I can't see what is different in your setup now, only that the two provided samples were perfectly recoverable. When you say no audio, do you get silence recorded instead of the chopping noise of Dolby data?

Sorry, here's some of the recent captures I tried. (https://drive.google.com/file/d/1mZLoFH8Shktn_JALIwX6UoHlHNJ9iXYW/view?usp=sharing)

It's all silence when I try to decode it.

j7n
31st August 2021, 04:59
All files in the last set of recordings are corrupted. They are all 16-bit with the least significant bits mangled by dither. See the zoomed in waveform (http://j7n.sytes.net/temp/toslink24bit.png). That noise in the gaps cannot be there.

Before recording, with S/PDIF connected but nothing playing on it, you want to make sure that the level meters of the incoming signal are below -130 dB. Ideally -inf. (no dither). -90 dB means that input has been converted or mixed with another signal source in 16-bit. The good news is that the first recordings were good, so it's possible to do it on your setup. But something went wrong.

Make sure the recording source is selected to only take S/PDIF input, not stereo out or line, that there are no other sounds playing, and that the system sampling rate is 48000 Hz. The timing clock should also be taken from the input signal, or there will be glitches and a corrupted frame every once in a while. The last part might be handled automatically. Maybe you can use ASIO or fake ASIO4ALL through WASAPI (NT 6) / KernelStreaming (XP) as the input, which can get the data more reliably compared to Wave or DirectSound. Reaper can be evaluated for free and offers all the input options, but it has a learning curve.

ENunn
31st August 2021, 08:10
I have ASIO4ALL installed luckily. I gave it a go with Adobe Audition. I think there's something wrong with the Waveforms.
https://i.imgur.com/lwS6Isn.png

I checked the noise, looks like it's under -130db. I don't think it's infinite because it's showing dots when I zoom in all the way.
https://i.imgur.com/fOS67C5.png

Here's my ASIO4ALL settings, do I need to change anything?
https://i.imgur.com/MzJZmPi.png

I also tried Reaper, I was able to get a Dolby Digital header, but when I converted the file to an ac3 it refused to play in MPC-HC and when I imported it in Audacity it just showed a half a second buzz.
https://i.imgur.com/2bOBy0n.png
https://i.imgur.com/ye4Rw2A.png

Next time I tried to record, it didn't capture the headers. C̶h̶a̶n̶g̶e̶d̶ ̶m̶y̶ ̶d̶e̶v̶i̶c̶e̶ ̶a̶n̶d̶ ̶R̶e̶a̶p̶e̶r̶ ̶t̶o̶ ̶1̶6̶-̶b̶i̶t̶,̶ ̶s̶a̶m̶e̶ ̶t̶h̶i̶n̶g̶.̶ ̶D̶o̶n̶'̶t̶ ̶k̶n̶o̶w̶ ̶w̶h̶a̶t̶'̶s̶ ̶u̶p̶.̶ ̶C̶h̶a̶n̶g̶e̶d̶ ̶b̶a̶c̶k̶ ̶t̶o̶ ̶2̶4̶-̶b̶i̶t̶,̶ ̶s̶a̶m̶e̶ ̶i̶s̶s̶u̶e̶,̶ ̶I̶ ̶s̶t̶i̶l̶l̶ ̶c̶a̶n̶'̶t̶ ̶g̶e̶t̶ ̶i̶t̶ ̶t̶o̶ ̶r̶e̶c̶o̶r̶d̶ ̶o̶r̶ ̶d̶e̶c̶o̶d̶e̶ ̶p̶r̶o̶p̶e̶r̶l̶y̶.̶ I had Reaper set to record in mono, Reaper seems to always default to mono for some reason. Now I can get headers consistently.

And what do you know, recording at 16-bit was a success! I got it to decode!!! I still can't get it working through Audacity though, that's probably because it doesn't support ASIO out of the box without compiling a version with ASIO. Same with Adobe Audition. Don't know what's up with that. If there's a free option that works without compiling, I'd love to know.

Now that I've gotten that taken care of, how do I sync this with my captured videos? At least properly? I know there's ffmpeg but I'm going in blind. Tried recording directly through Amarec, can't decode it.

j7n
31st August 2021, 09:04
MediaInfo indeed reacts to the SPDIF headers in 24-bit. But the tools that extract the native ac-3 are simple, and need continuous data frames without the 8 blank bits.

In Reaper you can create a project template for this purpose. In File -> Project settings set the desired location for files, bit depth, and make a track with a stereo source. Then save it under File -> Project templates.

I don't know other software, and stay with what I have already learned.

ENunn
24th December 2021, 06:04
Coming back to this post because I have a bit of a problem. Sometimes the channel will glitch out or Spectrum will add in a commercial, which makes the audio recording pause for a second. When I decode with bsconvert and try to sync audio, the audio will be out of sync at that point and I'm not sure how to fix this.

Is there any way I can prevent this or maybe add padding to the affected areas to keep everything in sync? Preferably without transcoding?

ENunn
10th February 2022, 19:23
Still looking for a solution. If anyone has any ideas, please share. I recorded a channel last night and it had a dropout which means syncing is impossible. Please help.

j7n
12th February 2022, 02:23
I don't know of a tool that would do this automatically. Bsconvert and beSplit discard everything that isn't a complete audio frame. The problem also occurs when splitting DTS-CD by cue points if there is garbage data at the start. If you can maintain sync as PCM before extraction, you could find the dropout by hand in an audio editor and copy silent AC-3 frames over the section. Prepare a long stretch of silence, maintaining the frame interval (find existing silence in the stream). Select the gap and overwrite from the clipboard. BeSplit takes a more brute-force approach in extraction, allowing the timing of the copy to be off.