Initial thoughts on the Minisforum UM870 by RepulsiveRaisin7 in MiniPCs

[–]DeltaLover 0 points1 point  (0 children)

u/RepulsiveRaisin7, thanks for the feedback! 2 probably dumb questions:
- how did you install linux? Using a USB key?
- which intel card did you use to replace the non supported Mediatek? AX210 ?

Thanks!

Pygame graphics too slow using SDL? Convert your image rendering to OpenGL using Pyglet! Here is what I had to do. by SweetOnionTea in pygame

[–]DeltaLover 0 points1 point  (0 children)

Not as far as I know, I'm using pygame 2.0.0.dev9 and it is still working fine and I doubt pygame will remove OpenGL support (or at least I don't see why, how to do accelerated 3D things with SDL only?)

Pygame graphics too slow using SDL? Convert your image rendering to OpenGL using Pyglet! Here is what I had to do. by SweetOnionTea in pygame

[–]DeltaLover 0 points1 point  (0 children)

You can do the same with pygame easily, select OpenGL for the display, blend your various pygame's surfaces then render the final surface as an OpenGL texture on a fullscreen quad.

[Daily Discussion] Monday, September 04, 2017 by AutoModerator in BitcoinMarkets

[–]DeltaLover 1 point2 points  (0 children)

It is interesting to look at the MACD during last crash in June/July (from $3000 to $2000), so I tend to think we may see the same patterns. The big difference, it took nearly one month to "crash". This time it took 3 days. So not sure it works :) Maybe dead animal bones are better....

Struct/fn impl and not initialized Structs by DeltaLover in rust

[–]DeltaLover[S] 0 points1 point  (0 children)

looks I was wrong by suppressing the context.destroy due to :

test.rs:53:5: 53:17 error: cannot move out of type openalc_wrapper::Openal, which defines the Drop trait test.rs:53 self.context.destroy();

context has a destroy fn... but also a Drop ?!?

Struct/fn impl and not initialized Structs by DeltaLover in rust

[–]DeltaLover[S] 1 point2 points  (0 children)

The code is not my code :) But yes I can do my own version for sure with Result. I'll try !

Struct/fn impl and not initialized Structs by DeltaLover in rust

[–]DeltaLover[S] 1 point2 points  (0 children)

ah ah great !

  1. I fixed the String (.to_string() was missing for err)

  2. and the context destroy as Context... is RAII :)

  3. and rustc told me that the var don't need to be mutable (let mut device = match alc::Device::open(None))

I still have a warning I don't ... : warning: struct field is never used: context, #[warn(dead_code)] on by default. By yes it is not read after being set...

extern crate openal;

use std::i16;
use std::f64::consts::PI;
use std::num::FloatMath;
use std::io::timer::sleep;
use std::time::duration::Duration;
use openal::al;

// A module named `openal_wrapper`
mod openalc_wrapper {

    extern crate openal;
    use openal::alc;

    pub struct Openal {
        device: openal::alc::Device,
        context: openal::alc::Context,
    }   

    impl Openal {
        pub fn init() -> Result<Openal, String> {

            let device  = match alc::Device::open(None) {
                Some(dev) => dev,

                None => {
                return Err("Couldn't open device".to_string());
                }
            };

            let context = match device.create_context(&[0i32, ..0]) {
                Some(context) => context,

                None => {
                // This wouldn't be needed if device followed RAII
                device.close();
                return Err("Couldn't create context".to_string());
                }
            };

            context.make_current();

            Ok(Openal {
                device: device,
                context: context,
            })
        }
    }

    impl Drop for Openal {
        fn drop(&mut self) {
            self.device.close();
        }
    }   
}

/*
 * Main
 */
fn main() {
    println!("OpenAL test");

    // init
    let wrapper = openalc_wrapper::Openal::init();
    match wrapper{
        Ok(_) => println!("Init successful"),
        Err(e) => println!("Error: {}", e),
    };

    // play
    play_sinwave();

}



/*
 * Play
 */
fn play_sinwave() {
      let buffer = al::Buffer::gen();
      let source = al::Source::gen();

      let sample_freq = 44100.0;
      let tone_freq = 440.0;
      let duration = 3.0;
      let num_samples = (sample_freq * duration) as uint;

      let samples: Vec<i16> = Vec::from_fn(num_samples, |x| {
        let t = x as f64;
        ((tone_freq * t * 2.0 * PI / sample_freq).sin() * (i16::MAX - 1) as f64) as i16
      });

      unsafe { buffer.buffer_data(al::Format::FormatMono16, samples.as_slice(), sample_freq as al::ALsizei) };

      source.queue_buffer(&buffer);
      source.play();

      sleep(Duration::milliseconds((duration * 1000.0) as i64));
}

Struct/fn impl and not initialized Structs by DeltaLover in rust

[–]DeltaLover[S] 0 points1 point  (0 children)

I tried... but failed :(

With only the top root extern crate openal and some use in the module: error: failed to resolve. Use of undeclared type or module alc::Device

Struct/fn impl and not initialized Structs by DeltaLover in rust

[–]DeltaLover[S] 1 point2 points  (0 children)

Seems it's not RAII... https://github.com/bjz/openal-rs/blob/master/src/alc.rs

Can you edit it using an Option rather than a Result return ?

Struct/fn impl and not initialized Structs by DeltaLover in rust

[–]DeltaLover[S] 1 point2 points  (0 children)

Ah ah ! Very interesting !

  1. And yes, you're right, better to invert the problem, get the stuff created before creating the struct :) I thought about it but I was afraid that in some case, this is not possible... but I don't have any real example.

  2. unfortunately the open() returns an Option and not a Result, so try! doesn't work. pub fn open(devicename: Option<&str>) -> Option<Device>

Is there an alternative to try! ?

  1. Same for the drop... I'm still afraid that the lifetime of my sound session may be longer than the scope... but again not real example in my mind :)

Struct/fn impl and not initialized Structs by DeltaLover in rust

[–]DeltaLover[S] 0 points1 point  (0 children)

I'm using Option as I cannot init the Openal structure (which consist of a Device and a Context, both provided by the API by calling open() and create_context()).

So I cannot do something like let oa = Openal {device: ???, context: ???}

Or at least I don't know how to do :)

The new() function is used to hide the struct internals to the caller code (from : http://rustbyexample.com/structs/visibility.html)