Monday, 8 September 2014

Getting a raspberry pi to show videos at start up.


A side project today at work was to get the Raspberry Pi to automatically display video files for our partner company.

The first part was getting the files to loop, I used the script from the learn adafruit site.

#!/bin/sh # get rid of the cursor so we don't see it when videos are running setterm -cursor off # set here the path to the directory containing your videos VIDEOPATH="/mnt/storage/videos" # you can normally leave this alone SERVICE="omxplayer" # now for our infinite loop! while true; do if ps ax | grep -v grep | grep $SERVICE > /dev/null then sleep 1; else for entry in $VIDEOPATH/* do clear omxplayer $entry > /dev/null done fi done

That was the easy bit.

The more challenging part was to autoplay the script on startup. After a number of fruitless trials, I discovered the raspberrypi.stackexchange font of wisdom.

Basically all you need to do is to add a line calling the script into the /etc/xdg/lxsession/LXDE/autostart file.

@/home/pi/bin/videoplayer.sh

Knowing the SSH address of the pi is helpful to safely shutdown - or just pull the power ;-)


Sunday, 27 July 2014

Adding Firstname, middle name and last names to a Ruby on Rails app

I was wanting to add first name, middle name and last name columns to a Ruby on Rails application (specifically the Rails-Devise tutorial from RailsApps).

After a couple of hours working through various sites I came up with three migrations:

timestamp_add_first_last_to_users.rb
class AddFirstLastToUsers < ActiveRecord::Migration
  
  def self.up
    change_table :users do |t|
      add_column :users, :first_name, :string
      add_column :users, :middle_name, :string
      add_column :users, :last_name, :string
    end
  end
  
  def self.down
    remove_column :users, :first_name
    remove_column :users, :middle_name
    remove_column :users, :last_name    
  end    
end

timestamp_update_names_to_users
class UpdateNamesToUsers < ActiveRecord::Migration
  def up
    User.all.each do |user|
      na=user.name.split(" ")
      nc=na.size
      user.first_name=na[0]
      user.last_name=na.last if na.size>1
      user.middle_name= na[1..na.size-1].join(" ") if na.size>2
      user.save!
    end
  end
  
  def down
    User.all.each do |user|
      user.name = [user.first_name, user.middle_name, user.last_name].compact.join(" ")
      user.save!
    end
  end
end

timestamp_remove_name_from_users.rb
class RemoveNameFromUsers < ActiveRecord::Migration
  def up
    remove_column :users, :name, :string
  end

  def down
    add_column :users, :name, :string
  end
end

This works, but is probably not the best solution.

If you have an easier way, please feel free to let me know.



Monday, 11 November 2013

Starting Week 2 of NaNoWriMo

I have done better this year at getting words put down than I did last year, and have managed to get around 1600 words added so far this month.

It's a big shame that the target is to have 50,000 words by the end of this November, and to achieve this I need to have written an average of 1667 words a day. My average so far is 146.

At this rate I will finish around 9th October 2014. Just in time to start next year's novel.

Not going to say much more at the moment, I'm going to have a go at putting some more ink on paper.

Sunday, 29 September 2013

Wine, coding, pizza and enumerize

Wine

Drunk Coding: Safer than
Drunk Driving, but only just.
For some reason, we didn't finish a bottle of wine last night, although to be fair we did have three glasses each, so I thought I'd better finish the bottle before it goes off.

Coding

I'm doing a little bit more coding on my game tracking application, and have found a link to a git branching model that appears useful, I'm going to have a good think about it and will try putting it in place.

I'm also looking into using the enumerize gem with the app to reduce the amount of database calls - I am only going to be tracking two versions of the game for the moment, so this sort of makes sense.

Pizza

In a random conversation about drunk coding, I jokingly mentioned a pizza. Then realised I really do fancy one. I'm trying to be good, so might make do with a bacon buttie instead. Although I'm still thinking about the pizza. I was thinking if I wait long enough, they'll all be shut and problem solved. Then I remembered that one chain is open until 5am.

I need to be in bed long before then though.

I must resist.


Saturday, 24 August 2013

lolcommits

Every now and again I look at the lolcommits gem, this allows a git user to take a snapshot each time that they commit code to their repository.

The only bit it took me a while to work out was the correct way to get the twitter option to post.

After some playing around I discovered the following sequence usually works:

lolcommits -p twitter --config

and type true when you get the prompt

enabled:

Once you have committed to your repo, then type

lolcommits -c

this will take a fresh screenshot from your latest commit and give you a url to authorise the tweet activity. Enter the url into a browser, then paste the code into the command prompt and all your future commits will be sent to annoy your followers.

Examples of this hideous idea are here (how many of these places do you recognise?):


















Sunday, 7 April 2013

Delays, Combs and Pitch


Introduction

Today I am going to talk a about the delay spectrum, showing examples of comb filtering, creating pitches with delays, slapback delays and synchronized long delays.

The Delay Spectrum

Terms used in delay effects

The delay time is how long the signal is delayed before being mixed in with the original signal.

We have dry and wet signals in filtering. A wet signal is the delayed signal. The dry signal is the undelayed signal.

Feedback is how much of the wet signal is returned back to itself. This is a gain stage and increases the amount of feedback that can be heard, and the time that the signal will continue to be heard.

Comb Filtering

Comb Filter Frequency Response Diagram
A comb filter adds a delayed version of a signal to itself, causing constructive and destructive interference. The frequency response of a comb filter has a series of evenly spaced spikes, making it look similar to a comb.

In this diagram, you can see the comb like signal. There is a 1mS delay between the original signal and both wet and dry signals are at 0dB. Where the two signals peak together, you can see that signal have been increased by 6dB. Where the signals are opposite there is around a 100dB notch.

Creating Pitches with Delays

With feedback applied and a 1mS delay, a clicking signal will appear to have a pitch caused by the addition of the dry signal with the fed back wet signal. If the delay is slowly increased, the pitch will appear to have a lower frequency. This relationship between the delay and the percieved pitch is a core part of generating electronic music.

Slapback Delay

A slapback delay has a medium delay time, typically between 75 and 250mS with very little or no feedback. This gives the effect of having sound reflecting from a wall with no additional echo's, or in other words making a similar sound to a room.

Synchronised Long Delays

A long delay gives a distinct echo to the sound, that matches what we would find in nature. It is important to synchronise the delay to the underlying musical content, in time with the quater notes for example.

To aid the listener, the wet signal needs to sound distinct to the dry original signal. A long delay can clash with harmonies and complex rhythms, so long delays need to be applied carefully and only after ensuring that the delay enhances the musical experience.

Reflection

Although a delay is a very simple concept, in actuality they are very complex effects to set up and make a usable and beneficial improvement to a song.

I would like to thank those of you that have read through and commented on my work, and wish you well with your coursework. I am finding it hard to believe that we're rapidly approaching the end of this course!

Sunday, 31 March 2013

Dynamic Range

Introduction

Welcome to my week 4 assignment for the Music Production course. Today I am going to look at Dynamic Range and some methods a producer can use to manipulate it.

Dynamic Range


This is simply the difference between the loudest and the quietest sounds in a recording.

The musicians give a natural dynamic range by following their score and playing louder or softer during their performance. The post-production work adjusts the dynamic range to give more feel to the music.

There are a number of areas where dynamic range can be adjusted:
  • Macro Scale>
  • Transients
  • Compression
  • Expansion
  • Dynamic Processors

The Macro Scale

The producer will look at the overall performance, and will see the relative levels between sections of the recording. They will ride the fader and automate the volume levels to strengthen the difference between verses and the chorus.

Transients

A transient is where the amplitude changes a lot during a short timescale. Examples of transient sounds include snare hits.

Compression

Compression reduces the dynamic range and brings volume levels to all the parts of the music into a similar level.

Expansion

Expansion increases the dynamic range, and gives more emphasis to sections of the music, either by bringing the perceived volume level up or down.

Dynamic Processors

A producer will use a dynamic processor to adjust the level of the audio following rules. Expanders, gates, compressors and limiters are types of dynamic processors.

Threshold

The point that a dynamic processor starts taking effect is known as the threshold. This is measured in dB, and a lower threshold (eg -30dB) means a large portion of the signal will be affected compared to a higher threshold of -5dB.

Ratio

The ratio is how much the processor changes the level once the threshold has been passed. The higher the ratio, the more the signal will change.

A ration of 6:1 means that if the input level is 6dB over the threshold, the output signal will be 1dB over threshold. The gain in this case has been reduced by 5dB.

Attack and Release

Attack and release provide a measure of control over how quickly a compressor acts.

The attack phase is the time when the compressor is decreasing gain to match the level that is set by the ratio. The release phase is when the compressor is increasing gain once the level has fallen below the threshold.

A compressor's attack and release are measured in mS, the time that it takes the gain to change a set amound of dB.

Soft and Hard Knees

The knee is how quickly the effect takes place. A soft knee slowly increases the compression ratio as the level increases and eventually reaches the compression ratio set by the user. The softer knee's reduces the audible change from uncompressed to compressed, especially for higher ratios.

Compression

A downward compressor reduces loud sounds over a certain threshold while quiet sounds remain unaffected.

An upward compressor will increase the loudness of sounds below the threshold while leaving louder sections unchanged.

Both downward and upward compression reduce the dynamic range of an audio signal.

Expanders


An expander increases the dynamic range of an audio signal, and typically are used to make quiet sounds even quieter by reducing the level of the signals that fall below a set threshold level.

A noise gate is a type of expander.

Reflection

I have given a brief introduction to Dynamic Range and the ways that a producer can change the level of a song.
The one thing the producer must consider about above all else is that the essential character of the music is not changed.

I would like to thank you for taking the time to read my discussion on Dynamic Range. There is so much to learn about the topic, and it will take a lifetime to fully understand the practical aspects.