TimeViewers / signalworks

MIT License
3 stars 2 forks source link

[Feature] Support 2-channel Audio #16

Closed j9ac9k closed 4 years ago

j9ac9k commented 5 years ago

Description

On opening of a two channel audio file, wave.py's read_wav method generates a MultiChannelError. Per earlier offline discussion, multi-channel audio files should create a MultiTrack object, consisting of separate tracks for each channel.

What I Did

Load a two channel audio file.

Traceback (most recent call last):
  File "/Users/ognyan/Developer/fred/src/main/python/fred/views/TableView.py", line 85, in currentChanged
    self.mainWindow._controller.selectFile(current)
  File "/Users/ognyan/Developer/fred/src/main/python/fred/controllers/controller.py", line 78, in selectFile
    track = self.getTrack(pathObj)
  File "/Users/ognyan/Developer/fred/src/main/python/fred/controllers/controller.py", line 86, in getTrack
    return Track.read(pathObj)
  File "/Users/ognyan/Developer/fred/.venv/lib/python3.7/site-packages/signalworks/tracking/tracking.py", line 155, in read
    return Wave.wav_read(path, channels, mmap)
  File "/Users/ognyan/Developer/fred/.venv/lib/python3.7/site-packages/signalworks/tracking/wave.py", line 269, in read_wav
    f"must select channel when loading file {path} with {value.shape[1]} channels"
signalworks.tracking.error.MultiChannelError: must select channel when loading file /Users/ognyan/Developer/fred/.venv/lib/python3.7/site-packages/scipy/io/tests/data/test-44100Hz-2ch-32bit-float-le.wav with 2 channels
lxkain commented 5 years ago

We can either change this so that all channels are loaded simultaneously, or have an additional GUI interaction that clarifies which channel(s) should be loaded. The latter will certainly be required for EDF and XDF support in the future.

j9ac9k commented 5 years ago

I would say we should load both channels simultaneously, if we already used all the disk in to access the file to begin with... Also I think the code to exclude a channel may be more complicated as well.

lxkain commented 5 years ago

Since this is signal works and not a GUI, how about by default we read everything, but optionally the user can specify a channel.

Do we return a Wave with a N-D array, or a MultiTrack with N Waves?

j9ac9k commented 5 years ago

I would think a multitrack with a wave object for each channel would be preferred, having a 2D wave object may introduce unnecessary complexity

lxkain commented 5 years ago

my preference as well

tuanad121 commented 5 years ago

I'm having a circular import problem :) Wave imports MultiTrack and MultiTrack imports Wave. We want Wave.read_wav() return MultiTrack. The MultiTrack need Wave in reading read_xdf(), read_edf(). Which is the best way to handle it?

j9ac9k commented 5 years ago

@tuanad121 and I discussed this, we should likely incorporate a signalworks.read() method that can return either a Track or MultiTrack.

lxkain commented 4 years ago

I am closing this issue because more recent conversations of this are in #24