lundi 31 août 2015

PortAudio: Playback lag at default frames-per-buffer

I'm trying to play audio in Go, asynchronously, using PortAudio. As far as I'm aware PortAudio handles its own threading, so I don't need to use any of Go's build-in concurrency stuff. I'm using libsndfile to load the file (also Go bindings). Here is my code:

type Track struct {
    stream   *portaudio.Stream
    playhead int
    buffer   []int32
}

func LoadTrackFilesize(filename string, loop bool, bytes int) *Track {
    // Load file
    var info sndfile.Info
    soundFile, err := sndfile.Open(filename, sndfile.Read, &info)
    if err != nil {
        fmt.Printf("Could not open file: %s\n", filename)
        panic(err)
    }
    buffer := make([]int32, bytes)
    numRead, err := soundFile.ReadItems(buffer)
    if err != nil {
        fmt.Printf("Error reading from file: %s\n", filename)
        panic(err)
    }
    defer soundFile.Close()

    // Create track
    track := Track{
        buffer: buffer[:numRead],
    }

    // Create stream
    stream, err := portaudio.OpenDefaultStream(
        0, 2, float64(44100), portaudio.FramesPerBufferUnspecified, track.playCallback,
    )
    if err != nil {
        fmt.Printf("Couldn't get stream for file: %s\n", filename)
    }
    track.stream = stream

    return &track
}

func (t *Track) playCallback(out []int32) {
    for i := range out {
        out[i] = t.buffer[(t.playhead+i)%len(t.buffer)]
    }
    t.playhead += len(out) % len(t.buffer)
}

func (t *Track) Play() {
    t.stream.Start()
}

Using these functions, after initialising PortAudio and all the rest, plays the audio track I supply - just. It's very laggy, and slows down the rest of my application (a game loop).

However, if I change the frames per buffer value from FramesPerBufferUnspecified to something high, say, 1024, the audio plays fine and doesn't interfere with the rest of my application.

Why is this? The PortAudio documentation suggests that using the unspecified value will 'choose a value for optimum latency', but I'm definitely not seeing that.

Additionally, when playing with this very high value, I notice some tiny artefacts - little 'popping' noises - in the audio.

Is there something wrong with my callback function, or anything else, that could be causing one or both of these problems?

Thanks.



via Chebli Mohamed

DockerHub Private Repo Login. More secure way?

I've seen articles such as this one about pulling from private repos and the "best" way to do it. What I understand is, if I want to automate any infrastructure to pull my docker images from dockerhub I need to:

  • Have a user I can login with.
  • Save the users creds in some application that will spin up my infrastructure (be it EC2 User data, a config file for ansible, or ENV variables in some API).
  • When the machine spins up it uses this user's credentials to login and place a token on the machine. All is well.

I'm wondering if there is any functionality to use application keys / tokens instead of needing to tie this to a user. It seems like it would be more secure/convenient if I could manage application keys to do have access to my user/organization's DockerHub account. Then I could yank the keys or change my password and not worry about the sky falling.

Is something like this available, coming, or is there a solution I haven't come across yet?

Thanks!



via Chebli Mohamed

Android Studio. Can i use startLockTask() on app X from app Y knowing the packageName of X?

The titles says it all. I want to start the LockTask introduced in lollipop on an app from another app. Can i do such thing ? Ty.



via Chebli Mohamed

How to add placeholder text to yii inputfield?

iam using clevertech an extension for YII, dose anybody know how i can add my own custom placeholder text inside the input. Below is an example of the input filed:

<?php echo $form->textFieldGroup(
            $model,
            'textField',
            array(
                'wrapperHtmlOptions' => array(
                    'class' => 'col-sm-5',
                ),
                'hint' => 'In addition to freeform text, any HTML5 text-based input appears like so.'
            )
        ); ?>



via Chebli Mohamed

Object prototype and class in Javascript

I'am working with javascript but I've doubts with my code because the function does not work as I want. This is my code:

classDescuentos = function () {
};

classDescuentos.prototype = {
var cellsEditar = function (row, column, columnfield, value, defaulthtml, columnproperties) {
            var data = grid.jqxGrid('getrowdata', row);
            var style = "";

            if (data.editar == 't' && data.apr_ger == 'f') {
                style = "display:block";
            } else {
                style = "display:none";
            }

            var html = "";
            var activarBotEnv = actBtn;
            html = "<div id='activarEdicion_" + row + "' style='width:99%;text-align:center;" + style + "' ><a href='#' id='editarHora' name='editarHora' title='Editar Total horas descontar' onclick=classDescuentos.prototype.editarHora(" + row + ");><img style='padding-bottom: 0px' height='17px' width='17px' src=../../../media/img/edit.png></a></div>";
            return html;
        };

editarHora: function (row) {
        var grid = $(this.gridData);
        grid.jqxGrid('setcolumnproperty', 'des_hor_ger_format', 'editable', true);
        grid.jqxGrid('begincelledit', row, "des_hor_ger_format");

        grid.on('cellendedit', function () {
            grid.jqxGrid('setcolumnproperty', 'des_hor_ger_format', 'editable', false);
        });
    }
};

Should allow edit the data of a cell of a jqxGrid of JQWidget and take the data that is entered but still leaves the original data before modifying it.

What am I doing wrong does not work?



via Chebli Mohamed

How to find the source table rows used by a big complex query

We have a huge Oracle SQL query in our project which is using many views and tables for source data.

Is there any way to find the list of rows fetched from each source table by this big query when I run it?

Basically what we are trying to do is to create the bare minimum number of rows in the source tables so that the outer most big query returns at least a single record.

I have tried to run the smaller queries individually. But it is really time consuming and tedious. So I was wondering if there is a smarter way of doing this.



via Chebli Mohamed

How do I use try, except?

I am currently making a program for the raspberry pi2 I just brought and with the help from some other members, have got it to work most of the time. however there are some case where it won't work because a field doesnt exist in the json if im correct. the code i have is:

import urllib.request
import json

r = urllib.request.urlopen("http://ift.tt/1NTgHGN").read()
rr = r.decode()

obj = json.loads(rr)

# filter only the b16 objects
b16_objs = filter(lambda a: a['routeName'] == 'B16',  obj['arrivals'])

if b16_objs:
# get the first item
b16 = next(b16_objs)
my_estimatedWait = b16['estimatedWait']

my_destination = b16['destination']
print(my_estimatedWait)

My problem is that when routeName B16 is not in the json, an error comes up. I've tried to use the try and catch feature but I could not get this to work. Is there another way of catching this error and displaying a message saying its not present?

The try and catch

try:
b16 = next(b16_objs)
except:
print("there are no records of this")



via Chebli Mohamed