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

Add support for OpenBSD platform via sndio host #493

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

AaronM04
Copy link

This adds support for the sndio host which is the default and only supported host on OpenBSD. I have tested all the examples for cpal and rodio, with no issues observed. If there are any improvements needed to bring this PR up to the standards of the cpal project, please let me know. :-)

@mitchmindtree
Copy link
Member

Thanks for the epic PR @AaronM04!

I don't have time to dig into this myself at the moment, not to mention my lack of experience with sndio & OpenBSD, however two steps that would help to land this are:

  1. Having one or more other OpenBSD users review and test the examples. I don't know of any other OpenBSD users personally, but if any are reading this it would help a lot if you could test and review!
  2. Adding a job to the Github CI workflow for OpenBSD + sndio. I'm not sure off the top of my head if it's possible to spin up a OpenBSD instance as easily as it is say Ubuntu. If it turns out not to be feasible with the github workflow, perhaps you have another recommendation for OpenBSD-specific CI? That said, I'd prefer we get this working with the github workflow in order to keep managing CI as simple as possible for maintainers.

Copy link

@blackgnezdo blackgnezdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Responding to review request since I happen to care about OpenBSD and Rust :)

The change is fairly massive so I didn't make it all the way to the end. Depending on your motivation and the prevailing conventions of RustAudio, some comments may be too nit-picky.

src/host/sndio/adapters.rs Outdated Show resolved Hide resolved
src/host/sndio/adapters.rs Outdated Show resolved Hide resolved
src/host/sndio/endian.rs Outdated Show resolved Hide resolved
src/host/sndio/mod.rs Outdated Show resolved Hide resolved
src/host/sndio/mod.rs Outdated Show resolved Hide resolved
/// Buffer overrun/underrun behavior -- ignore/sync/error?
behavior: BufferXrunBehavior,

/// If a buffer size was chosen, contains that value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The abundance of Optional suggests a huge state space. I suspect it can be reduced by refactoring InnerState type into an enum with a pruned set of fields that apply to specific stages of of the state machine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blackgnezdo I have fixed this. Please take a look when you get a chance. Thanks!

src/host/sndio/mod.rs Outdated Show resolved Hide resolved
let hdl = unsafe {
// The transmute is needed because this C string is *const u8 in one place but *const i8 in another place.
let devany_ptr = mem::transmute::<_, *const i8>(sndio_sys::SIO_DEVANY as *const _);
let nonblocking = true as i32;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might as we be written as 1 with an increase in readability, what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. I tend to favor boolean values as Rust bools, though the cast may be too confusing here.

)
};
if hdl.is_null() {
return Err(SndioError::DeviceNotAvailable);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do better and somehow report the errno? Probably applies everywhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try that here but when I checked errno for an error from sio_setpar it didn't set it.

src/host/sndio/mod.rs Outdated Show resolved Hide resolved
@blackgnezdo
Copy link

  1. Adding a job to the Github CI workflow for OpenBSD + sndio. I'm not sure off the top of my head if it's possible to spin up a OpenBSD instance as easily as it is say Ubuntu. If it turns out not to be feasible with the github workflow, perhaps you have another recommendation for OpenBSD-specific CI? That said, I'd prefer we get this working with the github workflow in order to keep managing CI as simple as possible for maintainers.

I don't know what it would take to get an OpenBSD CI on github, but as a point of reference, here's what it takes to get a GCE image of OpenBSD.
https://github.com/google/syzkaller/blob/master/tools/create-openbsd-gce-ci.sh

@grayed
Copy link

grayed commented Nov 3, 2020

  1. Adding a job to the Github CI workflow for OpenBSD + sndio. I'm not sure off the top of my head if it's possible to spin up a OpenBSD instance as easily as it is say Ubuntu. If it turns out not to be feasible with the github workflow, perhaps you have another recommendation for OpenBSD-specific CI? That said, I'd prefer we get this working with the github workflow in order to keep managing CI as simple as possible for maintainers.

FWIW, the sndio library is available on Linux, so you don't need OpenBSD to run CI for it: https://sndio.org/

@AaronM04
Copy link
Author

AaronM04 commented Nov 6, 2020

For CI, I think it will be more practical to use sndio on Linux (as @grayed mentioned) than to setup an OpenBSD VM as part of the github workflow. The one potential complication is getting sndio-sys as a dependency on linux, but only conditionally. Currently the dependency is conditional on cfg(target_os = "openbsd"). I am not very familiar with this part of Cargo/Rust so I would be very grateful for any assistance with this.

As for testing the workflow, should I just push to this branch? (it could be a lot of commits if it's trial and error that way)

@mitchmindtree
Copy link
Member

The one potential complication is getting sndio-sys as a dependency on linux, but only conditionally.

Perhaps we can add a linux-sndio cargo feature, and then conditionally include the sndio host with a cfg that looks something like:

#[cfg(or(target_os = "openbsd", and(target_os = "linux", feature = "linux-sndio")))]

@RustAudio/cpal-maintainers does this sound OK?

As for testing the workflow, should I just push to this branch? (it could be a lot of commits if it's trial and error that way)

Yeah that's totally fine, though perhaps rather than continuously adding new commits you could use git commit --amend on the last commit that adds the workflow and then force push it on each attempt? This is what I normally do when attempting to add a new workflow at least, not sure if there's a nicer way!

Copy link

@blackgnezdo blackgnezdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noted a few more things, but the whole change is too big to read in one sitting :(

Also, there's a bunch of CI generated complaints that probably need to be addressed.


fn open(&mut self) -> Result<(), SndioError> {
match self {
InnerState::Opened { .. } | InnerState::Running { .. } => Ok(()), // Already opened

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it a good idea to permit a duplicate open? I'd complain and return an SndioError.

// Transition to running
par.appbufsz = buffer_size as u32;
hdl.set_params(&par)?;
let mut tmp: HashMap<u32, sndio_sys::sio_par> = HashMap::new();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does turbo-fish not work here? It should be shorter.

hdl: SioHdl,

/// Map of sample rate to parameters.
sample_rate_to_par: HashMap<u32, sndio_sys::sio_par>,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashMap<u32, sndio_sys::sio_par> type seems pervasive. It probably deserves a well-named alias or even a newtype. I'm also partial to creating aliases for numeric types such that a sample rate and every other kind of u32 aren't easy to mix-up. Between these two, I'd probably have here:

rate_parameters: RateParameterMap,

unsafe impl Send for SioHdl {}

/// The shared state between Device and Stream. Responsible for closing handle when dropped.
enum InnerState {

This comment was marked as resolved.


unsafe impl Send for SioHdl {}

/// The shared state between Device and Stream. Responsible for closing handle when dropped.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should also list the permitted transitions unless they are fully controlled by the type impl?

}
}

unsafe impl Send for SioHdl {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably deserves a comment explaining unsafe: why it has to be unsafe, also why and under which assumptions it's OK.


inner_state.setup_stream(config)?;

let idx;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine declaration with assignment.

}

pub fn set_xrun_behavior(&mut self, b: BufferXrunBehavior) -> Result<(), SndioError> {
let mut inner_state = self.inner_state.lock().unwrap();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there's a way to return an error, why unwrap rather than complain? Seems to apply in all the cases below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it this way because only panics on the previous thread to have locked the mutex can cause an error to be returned from lock. I suppose it still makes sense to return a "thread panicked" error here.

}

/// Create an output stream.
fn build_output_stream_raw<D, E>(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like 50 lines of code largely similar to build_input_stream_raw, any chance you can figure out the common parts and de-dup?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent a lot of time trying this out and unfortunately I don't think this can be de-duped without adding another layer of Box around the callbacks, which would impact performance (albeit not by much).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(well, there are macros but that feels almost like obfuscating the code to me)


fn supported_config_from_par(par: &sndio_sys::sio_par, num_channels: u32) -> SupportedStreamConfig {
SupportedStreamConfig {
channels: num_channels as u16,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be a true comment to add? Otherwise it's not clear why u32 suddenly becomes u16.
// Conversion is courtesy of type mismatch between sndio and RustAudio.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, added verbatim!

* Add SampleRateMap with SampleRate keys rather than raw HashMap with
  u32 keys.
* Use FrameCount type alias rather than usize for buffer size.
* More robust error handling.
* Document InnerState state transitions.
@AaronM04
Copy link
Author

@blackgnezdo I finally was able to return to this. Please review when you have time. Thanks in advance! 😄

BTW I don't know what CI complaints you are referring to.

Copy link

@blackgnezdo blackgnezdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AaronM04, I wanted to play with the code but cargo build fails for me on openbsd-amd64-current:

   Compiling sndio-sys v0.0.1
error: failed to run custom build command for `sndio-sys v0.0.1`

Caused by:
  process didn't exit successfully: `/home/greg/s/cpal/target/debug/build/sndio-sys-c905c01512cca331/build-script-build` (exit code: 101)
  --- stdout
  cargo:rustc-link-lib=sndio
  cargo:rerun-if-changed=wrapper.h

  --- stderr
  thread 'main' panicked at 'Unable to find libclang: "couldn\'t find any valid shared libraries matching: [\'libclang.so\', \'libclang.so.*\'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"', /home/greg/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.53.3/src/lib.rs:1956:31
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Any clues?

src/host/sndio/mod.rs Show resolved Hide resolved
@AaronM04
Copy link
Author

Somehow I missed the notification for this. :/

@AaronM04, I wanted to play with the code but cargo build fails for me on openbsd-amd64-current:

   Compiling sndio-sys v0.0.1
error: failed to run custom build command for `sndio-sys v0.0.1`

Caused by:
  process didn't exit successfully: `/home/greg/s/cpal/target/debug/build/sndio-sys-c905c01512cca331/build-script-build` (exit code: 101)
  --- stdout
  cargo:rustc-link-lib=sndio
  cargo:rerun-if-changed=wrapper.h

  --- stderr
  thread 'main' panicked at 'Unable to find libclang: "couldn\'t find any valid shared libraries matching: [\'libclang.so\', \'libclang.so.*\'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"', /home/greg/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.53.3/src/lib.rs:1956:31
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Any clues?

Did it work back in November but not anymore? If so, I have no idea what the issue is.

If this is the first time you're trying to build it, run:

doas pkg_add llvm

I added this to https://github.com/mjkillough/sioctl-rs#installation

@AaronM04
Copy link
Author

The iOS build is failing but I suspect this is not due to any of my commits.

@blackgnezdo
Copy link

Somehow I missed the notification for this. :/
...

Any clues?

Did it work back in November but not anymore? If so, I have no idea what the issue is.

No, I had never tried to build your code before the first time I complained.

If this is the first time you're trying to build it, run:

doas pkg_add llvm

I added this to https://github.com/mjkillough/sioctl-rs#installation

I do have llvm package:

% pkg_info llvm
Information for inst:llvm-10.0.1p8
...

The library is available on the system:

% pkg_info -L llvm | grep 'libclang.*so'
...
/usr/local/lib/libclang-cpp.so.0.0
/usr/local/lib/libclang.so.8.1

Yet cargo build reports (for d419f0f):

  Compiling sndio-sys v0.0.1
error: failed to run custom build command for `sndio-sys v0.0.1`

Caused by:
  process didn't exit successfully: `/home/greg/s/cpal/target/debug/build/sndio-sys-cbc09558b43ecb1b/build-script-build` (exit code: 101)
  --- stdout
  cargo:rustc-link-lib=sndio
  cargo:rerun-if-changed=wrapper.h

  --- stderr
  thread 'main' panicked at 'Unable to find libclang: "couldn\'t find any valid shared libraries matching: [\'libclang.so\', \'libclang.so.*\'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"', /home/greg/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.53.3/src/lib.rs:1956:31
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Now, I bothered to read the error message and the resolution of my problem is:

% LIBCLANG_PATH=/usr/local/lib/libclang.so.8.1 cargo build
   Compiling sndio-sys v0.0.1
   Compiling cpal v0.12.1 (/home/greg/s/cpal)
    Finished dev [unoptimized + debuginfo] target(s) in 7.29s

I wonder why you don't have to set LIBCLANG_PATH.

@AaronM04
Copy link
Author

I wonder why you don't have to set LIBCLANG_PATH.

It turns out that I added export LIBCLANG_PATH=/usr/local/lib to my profile and forgot about it...

@blackgnezdo
Copy link

I proposed some code shrinking changes a minor refactoring. If this works, I can massage it a bit more.

blackgnezdo and others added 3 commits January 29, 2021 22:01
Avoids duplicating information with:
  * TypeSampleFormat to avoid redundant values
  * Sample trait for value conversion
  * Common data_from_vec fn

Indexing typically means a runtime check whereas iterators don't.
@AaronM04
Copy link
Author

AaronM04 commented Feb 1, 2021

@blackgnezdo thanks! It is quite an improvement. I merged your commits into this branch.

klemensn added a commit to klemensn/psst that referenced this pull request Nov 17, 2021
Done with editing Cargo.toml followed by `cargo update -p cpal`,
which, sadly, change a whole bunch of other dependencies.

This makes audio play, but two issues remain:

1. Playback speed is noticably slow.
2. Toggling play -> shows this error, although playback is successfully
   paused:
   ```
   [2021-11-17T16:03:04Z ERROR psst_core::audio::output] failed to stop stream: A backend-specific error has occurred: pausing is not implemented
   ```
"Add support for OpenBSD platform via sndio host"
RustAudio/cpal#493 is based on an older cpal
release;  maybe rebasing on top of HEAD and therefore bringing in the
cpal changes that current psst already uses helps with/fixes any of the
two issues?
klemensn added a commit to klemensn/psst that referenced this pull request Nov 18, 2021
Done with editing Cargo.toml followed by `cargo update -p cpal`,
which, sadly, change a whole bunch of other dependencies.

This makes audio play, but two issues remain:

1. Playback speed is noticably slow.
2. Toggling play -> shows this error, although playback is successfully
   paused:
   ```
   [2021-11-17T16:03:04Z ERROR psst_core::audio::output] failed to stop stream: A backend-specific error has occurred: pausing is not implemented
   ```
"Add support for OpenBSD platform via sndio host"
RustAudio/cpal#493 is based on an older cpal
release;  maybe rebasing on top of HEAD and therefore bringing in the
cpal changes that current psst already uses helps with/fixes any of the
two issues?
@klemensn
Copy link

Hi everyone!

Over at jpochyla/psst#191 psst switched to cpal and I'm working on OpenBSD support.
I'm using your feature branch to be able to play music at all, but unfortunately playback speed is noticably slow.
(before cpal, miniaudio was used and psst played music just fine on OpenBSD.)

My audio/rust/cpal/etc. foo is weak, hence I've only been testing cpal with psst.
Can you recommend another (possibly simpler) way of testing cpal's sndio support in this branch?
I'd like to help bring this forward in whatever way I can.

I've also rebased your branch onto latest cpal master and retested psst, but with no avail: playback speed is still too slow.

@AaronM04
Copy link
Author

AaronM04 commented Nov 19, 2021

Hey @klemensn ! 👋

Can you define "slow"? Which of these is it?

  • Stretched out/longer notes but the same pitch. A 4 minute song takes >4 minutes to play.
  • Lower pitch. A 4 minute song takes >4 minutes to play. If so, it could be that psst is expecting one sample rate but cpal is using another one.
  • Stuttering/choppy playback.

Lastly, is this an OpenBSD-specific problem with psst+cpal? I suspect not, but I just wanted to be sure.

EDIT: have you tried the example cpal programs on OpenBSD? What happens with those?

@klemensn
Copy link

psst reports 31 seconds of elapsed playback time while 60 seconds have passed
on the wall clock.

No other issues like stuttering or so, just playback speed.

Here are the outputs of cpal's examples built with cargo build --examples.
beep produces a since, but I don't know which frequency (the source code did
not immediately give away this information).

$ ./target/release/examples/feedback
Using input device: "sndio default device"
Using output device: "sndio default device"
Attempting to build both streams with f32 samples and `StreamConfig { channels: 1, sample_rate: SampleRate(48000), buffer_size: Default }`.
Successfully built streams.
Starting the input and output streams with `150` milliseconds of latency.
Playing for 3 seconds... 
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
input stream fell behind: try increasing latency
Done!
$ ./target/release/examples/enumerate
Supported hosts:
  [Sndio]
Available hosts:
  [Sndio]
sndio
  Default Input Device:
    Some("sndio default device")
  Default Output Device:
    Some("sndio default device")
  Devices: 
  1. "sndio default device"
    Default input stream config:
      SupportedStreamConfig { channels: 1, sample_rate: SampleRate(48000), buffer_size: Range { min: 480, max: 4800 }, sample_format: I16 }
    All supported input stream configs:
      1.1. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(48000), max_sample_rate: SampleRate(48000), buffer_size: Range { min: 480, max: 4800 }, sample_format: I16 }
      1.2. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(8000), max_sample_rate: SampleRate(8000), buffer_size: Range { min: 80, max: 800 }, sample_format: I16 }
      1.3. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(44100), max_sample_rate: SampleRate(44100), buffer_size: Range { min: 441, max: 4410 }, sample_format: I16 }
    Default output stream config:
      SupportedStreamConfig { channels: 1, sample_rate: SampleRate(48000), buffer_size: Range { min: 480, max: 4800 }, sample_format: I16 }
    All supported output stream configs:
      1.1. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(48000), max_sample_rate: SampleRate(48000), buffer_size: Range { min: 480, max: 4800 }, sample_format: I16 }
      1.2. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(8000), max_sample_rate: SampleRate(8000), buffer_size: Range { min: 80, max: 800 }, sample_format: I16 }
      1.3. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(44100), max_sample_rate: SampleRate(44100), buffer_size: Range { min: 441, max: 4410 }, sample_format: I16 }
$ ./target/release/examples/beep
Output device: sndio default device
Default output config: SupportedStreamConfig { channels: 1, sample_rate: SampleRate(48000), buffer_size: Range { min: 480, max: 4800 }, sample_format: I16 }

@klemensn
Copy link

FWIW, recording through cpal works correctly on OpenBSD.
aucat(1) plays the file in the correct speed, without problems.

$ ./target/release/examples/record_wav
Input device: sndio default device
Default input config: SupportedStreamConfig { channels: 1, sample_rate: SampleRate(48000), buffer_size: Range { min: 480, max: 4800 }, sample_format: I16 }
Begin recording...
Recording /home/kn/src/cpal/recorded.wav complete!
$ aucat -i /home/kn/src/cpal/recorded.wav

@AaronM04
Copy link
Author

@klemensn the beep example is a 440 Hz sine wave.

I see the same output as you for the feedback and enumerate examples (including the input stream fell behind: try increasing latency lines).

Try talking during the feedback example. Does your echoed voice sound normal?

I'll try it out with psst if I get some more time today.

@AaronM04
Copy link
Author

AaronM04 commented Nov 24, 2021

@klemensn I tried compiling psst after making it use the cpal from this branch, and I got this error from the souvlaki crate:

error[E0308]: mismatched types
  --> /home/aaron/.cargo/registry/src/github.com-1ecc6299db9ec823/souvlaki-0.4.0/src/platform/empty/mod.rs:13:9
   |
12 |     pub fn new(_config: PlatformConfig) -> Result<Self, Error> {
   |                                            ------------------- expected `Result<platform::platform::MediaControls, platform::platform::Error>` because of return type
13 |         Self
   |         ^^^^
   |         |
   |         expected enum `Result`, found struct `platform::platform::MediaControls`
   |         help: try using a variant of the expected enum: `Ok(Self)`
   |
   = note: expected enum `Result<platform::platform::MediaControls, platform::platform::Error>`
            found struct `platform::platform::MediaControls`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `souvlaki` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed

Did you encounter this error? If so, how did you fix it? Thanks.

Also, did you do anything nontrivial when updating this branch to cpal 0.13?

@klemensn
Copy link

Use my openbsd branch from jpochyla/psst#191 to build
on OpenBSD, it contains all quirks, incl. an update to souvlaki where I fixed
the error you ran into.

Speaking during the feedback example plays back as expected, i.e. without any
slow down, pitch or anything else.

Thanks for looking into this!

@AaronM04
Copy link
Author

AaronM04 commented Nov 29, 2021

@klemensn I was able to reproduce the issue with your psst branch (I did make one change to a Cargo.toml to use my local cpal repository though). I played a song I am familiar with and the voices sounded very low pitch (stretched out). I think it is either a sample-rate confusion or a stereo-mono confusion.

I also noticed an error when hitting pause:

[2021-11-29T21:14:24Z ERROR psst_core::audio::output] failed to stop stream: A backend-specific error has occurred: pausing is not implemented

This suggests two things need to be fixed in this branch before psst will be working with cpal on OpenBSD:

  • Fix the sample-rate or stereo-mono confusion. An example of the latter would be psst requesting stereo playback but cpal using mono -- this would cause everything to be one octave lower (half the frequency).

  • Implement pause/resume. Essentially the sndio system needs to be closed and re-created. EDIT: playback continues when I unpause, inexplicably! Maybe we don't need to fix this

Unfortunately, my time is over-committed so I can't take the lead in fixing these. However, I can definitely help another Rust developer understand the code that I wrote. I can also suggest where to do debugging or add print statements to better understand this.

klemensn added a commit to klemensn/psst that referenced this pull request Nov 30, 2021
Done with editing Cargo.toml followed by `cargo update -p cpal`,
which, sadly, change a whole bunch of other dependencies.

This makes audio play, but two issues remain:

1. Playback speed is noticably slow.
2. Toggling play -> shows this error, although playback is successfully
   paused:
   ```
   [2021-11-17T16:03:04Z ERROR psst_core::audio::output] failed to stop stream: A backend-specific error has occurred: pausing is not implemented
   ```
"Add support for OpenBSD platform via sndio host"
RustAudio/cpal#493 is based on an older cpal
release;  maybe rebasing on top of HEAD and therefore bringing in the
cpal changes that current psst already uses helps with/fixes any of the
two issues?
@klemensn
Copy link

@AaronM04 Thanks a bunch!

@jpochyla just committed further changes, specifically
jpochyla/psst@a774653
jpochyla/psst@df89890
which I rebased onto.

Something's still off as you can see in
jpochyla/psst@a4faacb
but playback speed is normal now and I can properly listen to songs!

So it seems as if @jpochyla followed your suggestion to fix "stereo-mono confusion".

The pause issue you mentioned is known (to me); I have not done anything yet to fix it.
Pausing does work, though, as does resuming playback.

klemensn added a commit to klemensn/psst that referenced this pull request Nov 30, 2021
Done with editing Cargo.toml followed by `cargo update -p cpal`,
which, sadly, change a whole bunch of other dependencies.

This makes audio play, but two issues remain:

1. Playback speed is noticably slow.
2. Toggling play -> shows this error, although playback is successfully
   paused:
   ```
   [2021-11-17T16:03:04Z ERROR psst_core::audio::output] failed to stop stream: A backend-specific error has occurred: pausing is not implemented
   ```
"Add support for OpenBSD platform via sndio host"
RustAudio/cpal#493 is based on an older cpal
release;  maybe rebasing on top of HEAD and therefore bringing in the
cpal changes that current psst already uses helps with/fixes any of the
two issues?
klemensn added a commit to klemensn/psst that referenced this pull request Dec 25, 2021
Done with editing Cargo.toml followed by `cargo update -p cpal`,
which, sadly, change a whole bunch of other dependencies.

This makes audio play, but two issues remain:

1. Playback speed is noticably slow.
2. Toggling play -> shows this error, although playback is successfully
   paused:
   ```
   [2021-11-17T16:03:04Z ERROR psst_core::audio::output] failed to stop stream: A backend-specific error has occurred: pausing is not implemented
   ```
"Add support for OpenBSD platform via sndio host"
RustAudio/cpal#493 is based on an older cpal
release;  maybe rebasing on top of HEAD and therefore bringing in the
cpal changes that current psst already uses helps with/fixes any of the
two issues?
klemensn added a commit to klemensn/psst that referenced this pull request Jan 5, 2022
Done with editing Cargo.toml followed by `cargo update -p cpal`,
which, sadly, change a whole bunch of other dependencies.

This makes audio play, but two issues remain:

1. Playback speed is noticably slow.
2. Toggling play -> shows this error, although playback is successfully
   paused:
   ```
   [2021-11-17T16:03:04Z ERROR psst_core::audio::output] failed to stop stream: A backend-specific error has occurred: pausing is not implemented
   ```
"Add support for OpenBSD platform via sndio host"
RustAudio/cpal#493 is based on an older cpal
release;  maybe rebasing on top of HEAD and therefore bringing in the
cpal changes that current psst already uses helps with/fixes any of the
two issues?
klemensn added a commit to klemensn/psst that referenced this pull request Jan 9, 2022
Done with editing Cargo.toml followed by `cargo update -p cpal`,
which, sadly, change a whole bunch of other dependencies.

This makes audio play, but two issues remain:

1. Playback speed is noticably slow.
2. Toggling play -> shows this error, although playback is successfully
   paused:
   ```
   [2021-11-17T16:03:04Z ERROR psst_core::audio::output] failed to stop stream: A backend-specific error has occurred: pausing is not implemented
   ```
"Add support for OpenBSD platform via sndio host"
RustAudio/cpal#493 is based on an older cpal
release;  maybe rebasing on top of HEAD and therefore bringing in the
cpal changes that current psst already uses helps with/fixes any of the
two issues?
klemensn added a commit to klemensn/psst that referenced this pull request Jan 16, 2022
Done with editing Cargo.toml followed by `cargo update -p cpal`,
which, sadly, change a whole bunch of other dependencies.

This makes audio play, but two issues remain:

1. Playback speed is noticably slow.
2. Toggling play -> shows this error, although playback is successfully
   paused:
   ```
   [2021-11-17T16:03:04Z ERROR psst_core::audio::output] failed to stop stream: A backend-specific error has occurred: pausing is not implemented
   ```
"Add support for OpenBSD platform via sndio host"
RustAudio/cpal#493 is based on an older cpal
release;  maybe rebasing on top of HEAD and therefore bringing in the
cpal changes that current psst already uses helps with/fixes any of the
two issues?
@midnadimple-zz
Copy link

just wanting to ping this request. i've tested it on my own repo. it fully merges into master and the examples run well. this should be noticed

@AaronM04
Copy link
Author

Hi @midnadimple . Thanks for the ping.

I think what this needs is another developer familiar with Rust, because I don't have much time to spend on this unfortunately.

There's only a bit of work left:

  1. Resolve the conflict (yes, there is one).
  2. Get another code review, and address any review feedback.
  3. Make sure tests pass
  4. Merge it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants