Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put structs common to backends in backend.common #706

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion torchaudio/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
get_sox_encoding_t,
get_sox_bool,
)
from .soundfile_backend import (
from .common import (
SignalInfo,
EncodingInfo,
)
31 changes: 31 additions & 0 deletions torchaudio/backend/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import Any, Optional, Tuple


class SignalInfo:
def __init__(self,
channels: Optional[int] = None,
rate: Optional[float] = None,
precision: Optional[int] = None,
length: Optional[int] = None) -> None:
self.channels = channels
self.rate = rate
self.precision = precision
self.length = length


class EncodingInfo:
def __init__(self,
encoding: Any = None,
bits_per_sample: Optional[int] = None,
compression: Optional[float] = None,
reverse_bytes: Any = None,
reverse_nibbles: Any = None,
reverse_bits: Any = None,
opposite_endian: Optional[bool] = None) -> None:
self.encoding = encoding
self.bits_per_sample = bits_per_sample
self.compression = compression
self.reverse_bytes = reverse_bytes
self.reverse_nibbles = reverse_nibbles
self.reverse_bits = reverse_bits
self.opposite_endian = opposite_endian
33 changes: 2 additions & 31 deletions torchaudio/backend/soundfile_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import Any, Optional, Tuple
from typing import Optional, Tuple

import torch
from torch import Tensor
Expand All @@ -8,6 +8,7 @@
module_utils as _mod_utils,
misc_ops as _misc_ops,
)
from .common import SignalInfo, EncodingInfo

if _mod_utils.is_module_available('soundfile'):
import soundfile
Expand All @@ -22,36 +23,6 @@
}


class SignalInfo:
def __init__(self,
channels: Optional[int] = None,
rate: Optional[float] = None,
precision: Optional[int] = None,
length: Optional[int] = None) -> None:
self.channels = channels
self.rate = rate
self.precision = precision
self.length = length


class EncodingInfo:
def __init__(self,
encoding: Any = None,
bits_per_sample: Optional[int] = None,
compression: Optional[float] = None,
reverse_bytes: Any = None,
reverse_nibbles: Any = None,
reverse_bits: Any = None,
opposite_endian: Optional[bool] = None) -> None:
self.encoding = encoding
self.bits_per_sample = bits_per_sample
self.compression = compression
self.reverse_bytes = reverse_bytes
self.reverse_nibbles = reverse_nibbles
self.reverse_bits = reverse_bits
self.opposite_endian = opposite_endian


@_mod_utils.requires_module('soundfile')
def load(filepath: str,
out: Optional[Tensor] = None,
Expand Down
2 changes: 1 addition & 1 deletion torchaudio/backend/sox_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module_utils as _mod_utils,
misc_ops as _misc_ops,
)
from .soundfile_backend import SignalInfo, EncodingInfo
from .common import SignalInfo, EncodingInfo

if _mod_utils.is_module_available('torchaudio._torchaudio'):
from torchaudio import _torchaudio
Expand Down