[Tutor] Controlling a device with ioctl's?
Hello to all. I'm working on writing a tool that will control a piece of hardware using ioctl's on its device node. Specifically, I'm trying to configure and tune a DVB-S receiver on Linux. Just for starters, I want to try opening the frontend and setting the LNB voltage. An example in C: ### /* all the normal #include's omitted */ #include linux/dvb/frontend.h fd = open(/dev/dvb/adapter1/frontend0, O_RDWR) r = ioctl (fd, FE_SET_VOLTAGE, SEC_VOLTAGE_18); if (r == -1) perror (ioctl FE_SET_VOLTAGE); ### The relevant definitions in linux/dvb/frontend.h: ### typedef enum fe_sec_voltage { SEC_VOLTAGE_13, SEC_VOLTAGE_18, SEC_VOLTAGE_OFF } fe_sec_voltage_t; ... #define FE_SET_VOLTAGE _IO('o', 67) /* fe_sec_voltage_t */ ### So, I wrote the following in Python: ### import fcntl fe_set_voltage = 67 sec_voltage_13 = 0 sec_voltage_18 = 1 sec_voltage_off = 2 fd = open(/dev/dvb/adapter1/frontend0, wb) fcntl.ioctl(fd, fe_set_voltage, sec_voltage_18) ### This fails with IOError: [Errno 95] Operation not supported. Considering I'm not too good with C, and know absolutely /nothing/ about device drivers or kernel code, I'm certain I'm missing something simple and obvious. Anyone want to set me straight? Thanks, -Joe ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Controlling a device with ioctl's?
A bit more work than I expected, but at least I have an idea what to do now. I'm working on writing a DVB binding based on the V4L2 binding you mentioned, currently about 30% complete - I can query the card's status! :) Thanks for the help so far, might post again if I run into more trouble. -Joe On Wed, 25 Aug 2010 00:21:12 +0200 Sander Sweers sander.swe...@gmail.com wrote: Maybe you can use the python v4l2 bindings from [1] as example how to use it for dvb. Not used it or have any experience with anything like this but it might help.. Greets Sander [1] http://pypi.python.org/pypi/v4l2 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Converting audio samples from 16-bit signed int to float?
Hello all. I'm writing a program that needs to capture audio from a soundcard and run FFTs to determine peak frequency for further processing. The soundcard's native capture format is 16-bit little-endian signed integer samples (values 0-65535), and of course the FFT function requires floating-point values (-1.0 - +1.0). So, what is the most efficient way to do the necessary conversion? I'm using the pyalsaaudio module to access the soundcard, if it matters. -Joe Veldhuis ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fast fourier transform libraries?
Hello to all. I'm working on a program that will need to do some simple signal analysis (namely, find the frequency of an audio signal) as part of its operation. Something like: - samples = list() for i in range(fft_length): samples.append(readSoundCard()) fft_bins = FFT(samples, sample_rate, window_function) for bin in fft_bins: #find strongest bin #return frequency in Hz corresponding to that bin - My question is, can someone recommend a library that provides an FFT function that will do what I want (i.e. take samples and return a list of bins)? Could be a binding to FFTW, or something else entirely. A search on PYPI returned nothing of interest. Any advice greatly appreciated! -Joe ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Generating audio tones?
Hello list. I'm trying to put together an AFSK modem in Python, and I have most of the code worked out. The last remaining issue will be generating the actual audio signal. Unfortunately, I have never written any kind of audio code before in any language, so I don't really know what I am doing. I did find some code that generated a single or DTMF tone, but it only worked if you let it fill the whole buffer with samples, less than that and it would get distorted at the end. That, and it didn't allow the frequency to be changed mid-run. I will need to generate sinusoidal tones of arbitrary length, shifting frequency as often as once every 8 milliseconds. The function should be something like this: def makesamples(frequency,length,phase): samples=[] for t in range(length): # ??? return samples Then, calling it: # ... for sample in makesamples(1200,40,phase): soundcard.write(chr(sample 0x00FF) + chr(sample 0xFF00 8)) # ... The code calling the function would probably have to figure out the phase for the next call based on the length of the output. For what it's worth, this will be running on an x86-64 Linux machine, using the ossaudiodev module to access the soundcard. Anyone think they can help? -Joe ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor