james-trayford / strauss

Sonification Tools and Resources for Analysis Using Sound Synthesis
Apache License 2.0
31 stars 3 forks source link

Simplify combining audio channels for > 2 channels #1

Open james-trayford opened 3 years ago

james-trayford commented 3 years ago

currently rely on ffmpeg-python wrapper to write surround sound wav files, but this may be overkill; requires writing of temporary files, and ffmpeg seems to scramble channel orders such that they need to be unscrambled using ad-hoc forder lists which had to be determined for each setup through trial and error and are now an extra property of the audio_channels object

Is it possible to:

JosephHinz commented 2 years ago

Hi James,

Here is the error message that I'm getting from the save_combined function-

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-10-1a20b17354ea> in <module>
      1 display_sonification(soni_M_neg, color='C1')
----> 2 soni_M_neg.save_combined('<directory/to/filename.wav>')

c:\users\josep\strauss\src\strauss\sonification.py in save_combined(self, fname, ffmpeg_output)
    111         print("Joning temporary .wav files...")
    112         (
--> 113             ff.filter(inputs, 'join', inputs=len(inputs), channel_layout=self.channels.setup)
    114             .output(fname)
    115             .overwrite_output()

~\anaconda3\lib\site-packages\ffmpeg\_run.py in run(stream_spec, cmd, capture_stdout, capture_stderr, input, quiet, overwrite_output)
    311     Returns: (out, err) tuple containing captured stdout and stderr data.
    312     """
--> 313     process = run_async(
    314         stream_spec,
    315         cmd,

~\anaconda3\lib\site-packages\ffmpeg\_run.py in run_async(stream_spec, cmd, pipe_stdin, pipe_stdout, pipe_stderr, quiet, overwrite_output)
    282     stdout_stream = subprocess.PIPE if pipe_stdout or quiet else None
    283     stderr_stream = subprocess.PIPE if pipe_stderr or quiet else None
--> 284     return subprocess.Popen(
    285         args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream
    286     )

~\anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    856                             encoding=encoding, errors=errors)
    857 
--> 858             self._execute_child(args, executable, preexec_fn, close_fds,
    859                                 pass_fds, cwd, env,
    860                                 startupinfo, creationflags, shell,

~\anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1309             # Start the process
   1310             try:
-> 1311                 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1312                                          # no special security
   1313                                          None, None,

FileNotFoundError: [WinError 2] The system cannot find the file specified
james-trayford commented 2 years ago

@JosephHinz thanks Joseph, interesting, perhaps it's a platform issue (I'm on mac, see e.g. https://stackoverflow.com/questions/45131495/the-system-cannot-find-the-file-specified-with-ffmpeg), I'll look into it.

For the non-surround sound applications you're looking at, you can use the new save_stereo method instead for now.

You can get these code changes by rebasing your fork onto the main branch of the original repo (see my email from last week).