Skip to content

Commit

Permalink
Add support for setting the attenuator.
Browse files Browse the repository at this point in the history
  • Loading branch information
dechamps committed Jan 20, 2019
1 parent eab08ba commit eac7034
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
27 changes: 27 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,38 @@ about what went wrong.
## Example configuration file

```toml
attenuator = false
bufferSizeSamples = 512
```

## Options reference

### Option `attenuator`

*Boolean*-typed option that determines if the QA401 hardware attenuator should
be engaged or not.

If the option is set to `true`, the QA401 attenuator will stay engaged.

If the option is set to `false`, the QA401 attenuator will be bypassed during
audio streaming.

Note that, contrary to the QuantAsylum Analyzer application, ASIO401 will not
adjust sample values in any way to account for the presence or absence of the
attenuator. In other words, defeating the attenuator has the effect of adding
20 dB to the samples coming from ASIO401.

**CAUTION:** do not apply high voltages to the QA401 inputs while the attenuator
is bypassed. See the QA401 User Manual for details.

Example:

```toml
attenuator = false
```

The default behaviour is to keep the attenuator engaged.

### Option `bufferSizeSamples`

*Integer*-typed option that determines which ASIO buffer size (in samples)
Expand Down
1 change: 1 addition & 0 deletions src/asio401/ASIO401/asio401.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ namespace asio401 {
// If we already have two buffers queued, we can start streaming.
// If we have more writes queued that the QA401 can store, we *have* to start streaming, otherwise the next FinishWrite() call will block indefinitely.
Log() << "Starting QA401";
preparedState.asio401.qa401.SetAttenuator(preparedState.asio401.config.attenuator);
preparedState.asio401.qa401.Start();
started = true;
}
Expand Down
1 change: 1 addition & 0 deletions src/asio401/ASIO401/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace asio401 {
}

void SetConfig(const toml::Table& table, Config& config) {
SetOption(table, "attenuator", config.attenuator);
SetOption(table, "bufferSizeSamples", config.bufferSizeSamples, ValidateBufferSize);
}

Expand Down
1 change: 1 addition & 0 deletions src/asio401/ASIO401/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace asio401 {

struct Config {
bool attenuator = true;
std::optional<int64_t> bufferSizeSamples;
};

Expand Down
5 changes: 5 additions & 0 deletions src/asio401/ASIO401/qa401.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ namespace asio401 {
Log() << "QA401 is reset";
}

void QA401::SetAttenuator(bool enabled) {
// According to QuantAsylum, the attenuator is bit mask 0x02. Also preserve the bits set in Reset().
WriteRegister(5, 4 | (enabled ? 0 : 0x02));
}

void QA401::Start() {
Log() << "Starting QA401 streaming";

Expand Down
1 change: 1 addition & 0 deletions src/asio401/ASIO401/qa401.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace asio401 {
QA401(std::string_view devicePath);

void Reset();
void SetAttenuator(bool enabled);
void Start();
void StartWrite(const void* buffer, size_t size);
void FinishWrite();
Expand Down

0 comments on commit eac7034

Please sign in to comment.