Example #1
0
void pc_speaker_free (pc_speaker_t *spk)
{
	pc_speaker_flush (spk);

	if (spk->drv != NULL) {
		snd_close (spk->drv);
	}
}
Example #2
0
int pc_speaker_set_driver (pc_speaker_t *spk, const char *driver, unsigned long srate)
{
	if (spk->drv != NULL) {
		snd_close (spk->drv);
	}

	spk->drv = snd_open (driver);

	if (spk->drv == NULL) {
		return (1);
	}

	spk->srate = srate;

	if (snd_set_params (spk->drv, 1, srate, 1)) {
		snd_close (spk->drv);
		spk->drv = NULL;
		return (1);
	}

	return (0);
}
Example #3
0
int main(int argc, char* argv[])
{
		snd_init();
		snd_open_stream();
		
		while(total_samples < MAX_SAMPLES) 
		{
				Pa_Sleep(1000);
		}
		
		snd_close();
		
		return 0;
}	
Example #4
0
io_error_t copy_file(const char *oldname, const char *newname)
{
  /* make newname a copy of oldname */
  int ifd, ofd;
  mus_long_t bytes, wb, total;
  char *buf = NULL;
  total = 0;
  ifd = OPEN(oldname, O_RDONLY, 0);
  if (ifd == -1) return(IO_CANT_OPEN_FILE);
  ofd = CREAT(newname, 0666);
  if (ofd == -1) 
    {
      snd_close(ifd, oldname);
      return(IO_CANT_CREATE_FILE);
    }
  buf = (char *)calloc(8192, sizeof(char));
  while ((bytes = read(ifd, buf, 8192)))
    {
      total += bytes;
      wb = write(ofd, buf, bytes);
      if (wb != bytes) 
	{
	  snd_close(ofd, newname);
	  snd_close(ifd, oldname);
	  free(buf); 
	  return(IO_WRITE_ERROR);
	}
    }
  snd_close(ifd, oldname);
  wb = disk_kspace(newname);
  snd_close(ofd, newname);
  free(buf);
  if (wb < 0)
    return(IO_DISK_FULL);
  return(IO_NO_ERROR);
}
Example #5
0
cvtfn_type find_cvt_to_fn(snd_type snd, char *buf)
{
    cvtfn_type cvtfn;
    /* find the conversion function */
    if (snd->format.bits == 8) cvtfn = cvt_to_8[snd->format.mode];
    else if (snd->format.bits == 16) cvtfn = cvt_to_16[snd->format.mode];
    else if (snd->format.bits == 24) cvtfn = cvt_to_24[snd->format.mode];
    else if (snd->format.bits == 32) cvtfn = cvt_to_32[snd->format.mode];
    else cvtfn = cvt_to_unknown;

    if (cvtfn == cvt_to_unknown) {
        char error[50];
        sprintf(error, "Cannot write %d-bit samples in mode %s",
                (int)snd->format.bits, snd_mode_to_string(snd->format.mode));
        free(buf);
        snd_close(snd);
        xlabort(error);
    }
    return cvtfn;
}
Example #6
0
void snd_reinit()
{
    snd_close();
    snd_init();
    snd_open_stream();
}
Example #7
0
bool ExportPCM(AudacityProject *project,
               wxString format, bool stereo, wxString fName,
               bool selectionOnly, double t0, double t1)
{
    wxMessageBox("In process of being rewritten, sorry...");

#if 0

    double rate = project->GetRate();
    wxWindow *parent = project;
    TrackList *tracks = project->GetTracks();

    int header = SND_HEAD_NONE;
#ifdef __WXMAC__
    bool trackMarkers = false;
#endif

    if (format == "WAV")
        header = SND_HEAD_WAVE;
    else if (format == "AIFF")
        header = SND_HEAD_AIFF;
    else if (format == "IRCAM")
        header = SND_HEAD_IRCAM;
    else if (format == "AU")
        header = SND_HEAD_NEXT;
#ifdef __WXMAC__
    else if (format == "AIFF with track markers") {
        header = SND_HEAD_AIFF;
        trackMarkers = true;
    }
#endif


    // Use snd library to export file

    snd_node sndfile;
    snd_node sndbuffer;

    sndfile.device = SND_DEVICE_FILE;
    sndfile.write_flag = SND_WRITE;
    strcpy(sndfile.u.file.filename, (const char *) fName);
    sndfile.u.file.file = 0;
    sndfile.u.file.header = header;
    sndfile.u.file.byte_offset = 0;
    sndfile.u.file.end_offset = 0;
    sndfile.u.file.swap = 0;
    sndfile.format.channels = stereo ? 2 : 1;
    sndfile.format.mode = SND_MODE_PCM;  // SND_MODE_FLOAT
    sndfile.format.bits = 16;
    sndfile.format.srate = int (rate + 0.5);

    int err;
    long flags = 0;

    err = snd_open(&sndfile, &flags);
    if (err) {
        wxMessageBox("Could not write to file.");
        return false;
    }

    sndbuffer.device = SND_DEVICE_MEM;
    sndbuffer.write_flag = SND_READ;
    sndbuffer.u.mem.buffer_max = 0;
    sndbuffer.u.mem.buffer = 0;
    sndbuffer.u.mem.buffer_len = 0;
    sndbuffer.u.mem.buffer_pos = 0;
    sndbuffer.format.channels = stereo ? 2 : 1;
    sndbuffer.format.mode = SND_MODE_PCM;        // SND_MODE_FLOAT
    sndbuffer.format.bits = 16;
    sndbuffer.format.srate = int (rate + 0.5);

    double timeStep = 10.0;      // write in blocks of 10 secs

    wxProgressDialog *progress = NULL;
    wxYield();
    wxStartTimer();
    wxBusyCursor busy;
    bool cancelling = false;

    double t = t0;

    while (t < t1 && !cancelling) {

        double deltat = timeStep;
        if (t + deltat > t1)
            deltat = t1 - t;

        sampleCount numSamples = int (deltat * rate + 0.5);

        Mixer *mixer = new Mixer(stereo ? 2 : 1, numSamples, true, rate);
        wxASSERT(mixer);
        mixer->Clear();

        char *buffer = new char[numSamples * 2 * sndbuffer.format.channels];
        wxASSERT(buffer);

        TrackListIterator iter(tracks);
        VTrack *tr = iter.First();
        while (tr) {
            if (tr->GetKind() == VTrack::Wave) {
                if (tr->selected || !selectionOnly) {
                    if (tr->channel == VTrack::MonoChannel)
                        mixer->MixMono((WaveTrack *) tr, t, t + deltat);
                    if (tr->channel == VTrack::LeftChannel)
                        mixer->MixLeft((WaveTrack *) tr, t, t + deltat);
                    if (tr->channel == VTrack::RightChannel)
                        mixer->MixRight((WaveTrack *) tr, t, t + deltat);
                }
            }
            tr = iter.Next();
        }

        sampleType *mixed = mixer->GetBuffer();

        long b2 = snd_convert(&sndfile, buffer,   // to
                              &sndbuffer, mixed, numSamples);     // from

        snd_write(&sndfile, buffer, b2);

        t += deltat;

        if (!progress && wxGetElapsedTime(false) > 500) {

            wxString message;

            if (selectionOnly)
                message =
                    wxString::
                    Format("Exporting the selected audio as a %s file",
                           (const char *) format);
            else
                message =
                    wxString::
                    Format("Exporting the entire project as a %s file",
                           (const char *) format);

            progress =
                new wxProgressDialog("Export",
                                     message,
                                     1000,
                                     parent,
                                     wxPD_CAN_ABORT |
                                     wxPD_REMAINING_TIME | wxPD_AUTO_HIDE);
        }
        if (progress) {
            cancelling =
                !progress->Update(int (((t - t0) * 1000) / (t1 - t0) + 0.5));
        }

        delete mixer;
        delete[]buffer;
    }

    snd_close(&sndfile);

#ifdef __WXMAC__

    FSSpec spec;

    wxMacFilename2FSSpec(fName, &spec);

    if (trackMarkers) {
        // Export the label track as "CD Spin Doctor" files

        LabelTrack *labels = NULL;
        TrackListIterator iter(tracks);
        VTrack *t = iter.First();
        while (t && !labels) {
            if (t->GetKind() == VTrack::Label)
                labels = (LabelTrack *) t;
            t = iter.Next();
        }
        if (labels) {
            FSpCreateResFile(&spec, 'AIFF', AUDACITY_CREATOR, 0);
            int resFile = FSpOpenResFile(&spec, fsWrPerm);
            if (resFile == -1) {
                int x = ResError();
            }
            if (resFile != -1) {
                UseResFile(resFile);

                int numLabels = labels->mLabels.Count();
                for (int i = 0; i < numLabels; i++) {
                    int startBlock = (int) (labels->mLabels[i]->t * 75);
                    int lenBlock;
                    if (i < numLabels - 1)
                        lenBlock =
                            (int) ((labels->mLabels[i + 1]->t -
                                    labels->mLabels[i]->t) * 75);
                    else
                        lenBlock =
                            (int) ((tracks->GetMaxLen() -
                                    labels->mLabels[i]->t) * 75);
                    int startSample = startBlock * 1176 + 54;
                    int lenSample = lenBlock * 1176 + 54;

                    Handle theHandle = NewHandle(50);
                    HLock(theHandle);
                    char *data = (char *) (*theHandle);
                    *(int *) &data[0] = startSample;
                    *(int *) &data[4] = lenSample;
                    *(int *) &data[8] = startBlock;
                    *(int *) &data[12] = lenBlock;
                    *(short *) &data[16] = i + 1;

                    wxString title = labels->mLabels[i]->title;
                    if (title.Length() > 31)
                        title = title.Left(31);
                    data[18] = title.Length();
                    strcpy(&data[19], (const char *) title);

                    HUnlock(theHandle);
                    AddResource(theHandle, 'SdCv', 128 + i, "\p");
                }
                CloseResFile(resFile);

                wxMessageBox("Saved track information with file.");
            }
        }
    }

    FInfo finfo;
    if (FSpGetFInfo(&spec, &finfo) == noErr) {
        switch (header) {
        case SND_HEAD_AIFF:
            finfo.fdType = 'AIFF';
            break;
        case SND_HEAD_IRCAM:
            finfo.fdType = 'IRCA';
            break;
        case SND_HEAD_NEXT:
            finfo.fdType = 'AU  ';
            break;
        case SND_HEAD_WAVE:
            finfo.fdType = 'WAVE';
            break;
        }

        finfo.fdCreator = AUDACITY_CREATOR;

        FSpSetFInfo(&spec, &finfo);
    }
#endif

    if (progress)
        delete progress;

    return true;

#endif

    return false;

}
Example #8
0
void finish_audio(snd_type player)
{
    /* note that this is a busy loop! */
    while (snd_flush(player) != SND_SUCCESS) ;
    snd_close(player);
}
Example #9
0
sample_type sound_save_array(LVAL sa, long n, snd_type snd, 
                             char *buf, long *ntotal, snd_type player)
{
    long i, chans;
    long buflen;
    sound_state_type state;
    double start_time = HUGE_VAL;
    float *float_bufp;
    LVAL sa_copy;
    long debug_unit;    /* print messages at intervals of this many samples */
    long debug_count;   /* next point at which to print a message */
    sample_type max_sample = 0.0F;
    cvtfn_type cvtfn;

    *ntotal = 0;

    /* THE ALGORITHM: first merge floating point samples from N channels
     * into consecutive multi-channel frames in buf.  Then, treat buf
     * as just one channel and use one of the cvt_to_* functions to
     * convert the data IN PLACE in the buffer (this is ok because the
     * converted data will never take more space than the original 32-bit
     * floats, so the converted data will not overwrite any floats before
     * the floats are converted
     */

    /* if snd_expr was simply a symbol, then sa now points to
        a shared sound_node.  If we read samples from it, then
        the sounds bound to the symbol will be destroyed, so
        copy it first.  If snd_expr was a real expression that
        computed a new value, then the next garbage collection
        will reclaim the sound array.  See also sound_save_sound()
    */
    chans = getsize(sa);
    if (chans > MAX_SND_CHANNELS) {
        xlerror("sound_save: too many channels", sa);
        free(buf);
        snd_close(snd);
    }
    xlprot1(sa);
    sa_copy = newvector(chans);
    xlprot1(sa_copy);

    /* Why do we copy the array into an xlisp array instead of just
     * the state[i] array? Because some of these sounds may reference
     * the lisp heap. We must put the sounds in an xlisp array so that
     * the gc will find and mark them. xlprot1(sa_copy) makes the array
     * visible to gc.
     */
    for (i = 0; i < chans; i++) {
        sound_type s = getsound(getelement(sa, i));
        setelement(sa_copy, i, cvsound(sound_copy(s)));
    }
    sa = sa_copy;	/* destroy original reference to allow GC */

    state = (sound_state_type) malloc(sizeof(sound_state_node) * chans);
    for (i = 0; i < chans; i++) {
        state[i].sound = getsound(getelement(sa, i));
        state[i].scale = state[i].sound->scale;
D       nyquist_printf("save scale factor %d = %g\n", (int)i, state[i].scale);
        state[i].terminated = false;
        state[i].cnt = 0;   /* force a fetch */
        start_time = min(start_time, state[i].sound->t0);
    }

    for (i = 0; i < chans; i++) {
        if (state[i].sound->t0 > start_time)
            sound_prepend_zeros(state[i].sound, start_time);
    }

    /* for debugging */
/*    printing_this_sound = s;*/

    cvtfn = find_cvt_to_fn(snd, buf);

#ifdef MACINTOSH
    if (player) {
        gprintf(TRANS, "Playing audio: Click and hold mouse button to stop playback.\n");
    }
#endif

    debug_unit = debug_count = (long) max(snd->format.srate, 10000.0);

    while (n > 0) {
        /* keep the following information for each sound:
            has it terminated?
            pointer to samples
            number of samples remaining in block
           scan to find the minimum remaining samples and
           output that many in an inner loop.  Stop outer
           loop if all sounds have terminated
         */
        int terminated = true;
        int togo = n;
        int j;
        float peak;

        oscheck();

        for (i = 0; i < chans; i++) {
            if (state[i].cnt == 0) {
                if (sndwrite_trace) {
                    nyquist_printf("CALLING SOUND_GET_NEXT "
                                   "ON CHANNEL %d (%p)\n",
                                   (int)i, state[i].sound);
                    sound_print_tree(state[i].sound);
                }
                state[i].ptr = sound_get_next(state[i].sound,
                                   &(state[i].cnt))->samples;
                if (sndwrite_trace) {
                    nyquist_printf("RETURNED FROM CALL TO SOUND_GET_NEXT "
                                   "ON CHANNEL %d\n", (int)i);
                }
                if (state[i].ptr == zero_block->samples) {
                    state[i].terminated = true;
                }
            }
            if (!state[i].terminated) terminated = false;
            togo = min(togo, state[i].cnt);
        }

        if (terminated) break;

        float_bufp = (float *) buf;
        for (j = 0; j < togo; j++) {
            for (i = 0; i < chans; i++) {
                double s = *(state[i].ptr++) * state[i].scale; 
                *float_bufp++ = (float) s;
            }
        }
        // we're treating sound as mono for the conversion, so multiply
        // togo by chans to get proper number of samples, and divide by
        // chans to convert back to frame count required by snd_write
        buflen = (*cvtfn)((void *) buf, (void *) buf, togo * chans, 1.0F, 
                          &peak) / chans;
        if (peak > max_sample) max_sample = peak;
#ifdef MACINTOSH
        if (Button()) {
            if (player) {
                snd_reset(player);
            }
            gprintf(TRANS, "\n\nStopping playback...\n\n\n");
            break;
        }
#endif

        if (snd->u.file.file != -1) snd_write(snd, (void *) buf, buflen);
        if (player) write_to_audio(player, (void *) buf, buflen);

        n -= togo;
        for (i = 0; i < chans; i++) {
            state[i].cnt -= togo;
        }
        *ntotal += togo;
        if (*ntotal > debug_count) {
            gprintf(TRANS, " %d ", *ntotal);
            fflush(stdout);
            debug_count += debug_unit;
        }
    }
    gprintf(TRANS, "total samples: %d x %d channels\n",
           *ntotal, chans);

    /* references to sounds are shared by sa_copy and state[].
     * here, we dispose of state[], allowing GC to do the
     * sound_unref call that frees the sounds. (Freeing them now
     * would be a bug.)
     */
    free(state);
    xlpop();
    return max_sample;
}
Example #10
0
double sound_overwrite(
  LVAL snd_expr,
  long n,
  unsigned char *filename,
  long byte_offset,
  long header,
  long mode,
  long bits,
  long swap,
  double sr,
  long nchans,
  double *duration)
{
    LVAL result;
    char *buf;
    char error[140];
    long ntotal;
    double max_sample;
    snd_node snd;
    long flags;

    snd.device = SND_DEVICE_FILE;
    snd.write_flag = SND_OVERWRITE;
    strcpy(snd.u.file.filename, (char *) filename);
    snd.u.file.header = header;
    snd.u.file.byte_offset = byte_offset;
    snd.format.channels = nchans;
    snd.format.mode = mode;
    snd.format.bits = bits;
    snd.u.file.swap = swap;
    snd.format.srate = sr;

    if ((buf = (char *) malloc(max_sample_block_len * MAX_SND_CHANNELS *
                                  sizeof(float))) == NULL) {
        xlabort("snd_overwrite: couldn't allocate memory");
    }

    if (snd_open(&snd, &flags) != SND_SUCCESS) {
        sprintf(error,
                "snd_overwrite: cannot open file %s and seek to %d", 
                filename, (int)byte_offset);
        free(buf);
        xlabort(error);
    }

    result = xleval(snd_expr);
    /* BE CAREFUL - DO NOT ALLOW GC TO RUN WHILE RESULT IS UNPROTECTED */
    if (vectorp(result)) {
        /* make sure all elements are of type a_sound */
        long i = getsize(result);
        if (nchans != i) {
            sprintf(error, "%s%d%s%d%s", 
                    "snd_overwrite: number of channels in sound (",
                    (int)i,
                    ") does not match\n    number of channels in file (",
                    (int)nchans,
                    ")");
            free(buf);
            snd_close(&snd);
            xlabort(error);
        }
        while (i > 0) {
            i--;
            if (!exttypep(getelement(result, i), a_sound)) {
                free(buf);
                snd_close(&snd);
                xlerror("sound_save: array has non-sound element",
                         result);
            }
        }
        /* assume all are the same: */
        if (sr != getsound(getelement(result, 0))->sr) {
            sprintf(error, "%s%g%s%g%s",
                    "snd_overwrite: sample rate in sound (",
                    getsound(getelement(result, 0))->sr,
                    ") does not match\n    sample rate in file (",
                    sr,
                    ")"); 
            free(buf);
            snd_close(&snd);
            xlabort(error);
        }
        
        max_sample = sound_save_array(result, n, &snd, buf, &ntotal, NULL);
        *duration = ntotal / sr;
    } else if (exttypep(result, a_sound)) {
        if (nchans != 1) {
            sprintf(error, "%s%s%d%s", 
                    "snd_overwrite: number of channels in sound (1",
                    ") does not match\n    number of channels in file (",
                    (int)nchans,
                    ")");
            free(buf);
            snd_close(&snd);
            xlabort(error);
        }
            
        if (sr != getsound(result)->sr) {
            sprintf(error, "%s%g%s%g%s",
                    "snd_overwrite: sample rate in sound (",
                    getsound(result)->sr,
                    ") does not match\n    sample rate in file (",
                    sr,
                    ")"); 
            free(buf);
            snd_close(&snd);
            xlabort(error);
        }
        
        max_sample = sound_save_sound(result, n, &snd, buf, &ntotal, NULL);
        *duration = ntotal / sr;
    } else {
        free(buf);
        snd_close(&snd);
        xlerror("sound_save: expression did not return a sound",
                 result);
        max_sample = 0.0;
    }
    free(buf);
    snd_close(&snd);
    return max_sample;
}
Example #11
0
double sound_save(
  LVAL snd_expr,
  long n,
  unsigned char *filename,
  long format,
  long mode,
  long bits,
  long swap,
  double *sr,
  long *nchans,
  double *duration,
  LVAL play)
{
    LVAL result;
    char *buf;
    long ntotal;
    double max_sample;
    snd_node snd;
    snd_node player;
    long flags;

    snd.device = SND_DEVICE_FILE;
    snd.write_flag = SND_WRITE;
    strcpy(snd.u.file.filename, (char *) filename);
    snd.u.file.file = -1;	/* this is a marker that snd is unopened */
    snd.u.file.header = format;
    snd.format.mode = mode;
    snd.format.bits = bits;
    snd.u.file.swap = swap;

    player.device = SND_DEVICE_AUDIO;
    player.write_flag = SND_WRITE;
    player.u.audio.devicename[0] = '\0';
    player.u.audio.descriptor = NULL;
    player.u.audio.protocol = SND_COMPUTEAHEAD;
    player.u.audio.latency = 1.0;
    player.u.audio.granularity = 0.0;

    if ((buf = (char *) malloc(max_sample_block_len * MAX_SND_CHANNELS *
                                  sizeof(float))) == NULL) {
        xlabort("snd_save -- couldn't allocate memory");
    }

    result = xleval(snd_expr);
    /* BE CAREFUL - DO NOT ALLOW GC TO RUN WHILE RESULT IS UNPROTECTED */
    if (vectorp(result)) {
        /* make sure all elements are of type a_sound */
        long i = getsize(result);
        *nchans = snd.format.channels = i;
        while (i > 0) {
            i--;
            if (!exttypep(getelement(result, i), a_sound)) {
                xlerror("sound_save: array has non-sound element",
                         result);
            }
        }
        /* assume all are the same: */
        *sr = snd.format.srate = getsound(getelement(result, 0))->sr; 

        /* note: if filename is "", then don't write file; therefore,
         * write the file if (filename[0])
         */ 
        if (filename[0] && snd_open(&snd, &flags) != SND_SUCCESS) {
            xlabort("snd_save -- could not open sound file");
        }
        
        play = prepare_audio(play, &snd, &player);

        max_sample = sound_save_array(result, n, &snd,
                         buf, &ntotal, (play == NIL ? NULL : &player));
        *duration = ntotal / *sr;
        if (filename[0]) snd_close(&snd);
        if (play != NIL) finish_audio(&player);
    } else if (exttypep(result, a_sound)) {
        *nchans = snd.format.channels = 1;
        *sr = snd.format.srate = (getsound(result))->sr;
        if (filename[0] && snd_open(&snd, &flags) != SND_SUCCESS) {
            xlabort("snd_save -- could not open sound file");
        }

        play = prepare_audio(play, &snd, &player);

        max_sample = sound_save_sound(result, n, &snd,
                        buf, &ntotal, (play == NIL ? NULL : &player));
        *duration = ntotal / *sr;
        if (filename[0]) snd_close(&snd);
        if (play != NIL) finish_audio(&player);
    } else {
        xlerror("sound_save: expression did not return a sound",
                 result);
        max_sample = 0.0;
    }
    free(buf);
    return max_sample;
}
Example #12
0
void power_off_process(void)
{
	struct  YCbCrColor bgcolor;
	extern struct rfm_device*   g_rfm_dev;
	extern struct scart_device* g_scart_dev;

#ifdef DVR_PVR_SUPPORT
	api_pvr_clear_up_all();
#endif	

	// SE: Mute before scart power off to avoid noise
	api_audio_set_mute(TRUE);

#if defined(HW_SS830C)||defined(HW_SS830C2)
	//Wirte GPIO#5 to high to avoid noise (used on SS830C)
	HAL_GPIO_BIT_DIR_SET(5, HAL_GPIO_O_DIR);
	HAL_GPIO_BIT_SET(5, 1);
#endif

	api_Scart_TVSAT_Switch(0);
	api_Scart_Power_OnOff(0);
	api_Scart_RGB_OnOff(0);/*CVBS mode*/
#ifdef VDAC_USE_SVIDEO_TYPE
	api_Svideo_OnOff(0);
#endif
	api_Scart_OutPut_Switch(0);
	SetLNBShortDetect(0);
	Set12VShortDetect(0);
	api_LNB_power(0);
#if(SYS_12V_SWITCH == SYS_FUNC_ON)
	 api_diseqc_set_12v(g_nim_dev, 0);
#endif    

#ifdef USB_MP_SUPPORT
	if(system_state == SYS_STATE_USB_MP)
	{
		ap_udisk_close();
	}
#endif

#ifndef NEW_DEMO_FRAME
	if(hde_get_mode() != VIEW_MODE_MULTI)
	    UIChChgStopProg(TRUE);    
#endif

#if	(TTX_ON == 1)
	ttx_enable(FALSE);
#endif
#if (SUBTITLE_ON == 1)
	subt_enable(FALSE);
#endif
	sie_close();

	OSD_ShowOnOff(OSDDRV_OFF);
#ifdef NEW_DEMO_FRAME
	sim_close_monitor(0);
#else
	si_monitor_off(0xFFFFFFFF);
#endif
	stop_tdt();
	epg_off();
	vpo_win_onoff(g_vpo_dev, FALSE);
#ifdef DUAL_VIDEO_OUTPUT
	if(g_sd_vpo_dev != NULL)
		vpo_win_onoff(g_sd_vpo_dev,TRUE);
#endif
	dm_set_onoff(0);

	bgcolor.uY = 16;
	bgcolor.uCb = 128;
	bgcolor.uCr = 128;		
	vpo_ioctl(g_vpo_dev,VPO_IO_SET_BG_COLOR,(UINT32)&bgcolor);

	//close drivers	
	dmx_stop( g_dmx_dev);
	dmx_close( g_dmx_dev);
    if (g_dmx_dev2)
    {
    	dmx_stop(g_dmx_dev2);
	    dmx_close(g_dmx_dev2);
    }
	deca_stop(g_deca_dev,0,ADEC_STOP_IMM);
	deca_close(g_deca_dev);
	vdec_close(g_decv_dev);

// Power HDMI phy at standby mode.
#ifdef HDTV_SUPPORT
	struct hdmi_device *hdmi_dev;
	hdmi_dev = (struct hdmi_device *)dev_get_by_id(HLD_DEV_TYPE_HDMI, 0);
	if (hdmi_dev != NULL)
	{
		if (SUCCESS != hdmi_dev->close(hdmi_dev))
		{
			PRINTF("hdmi_close failed!!\n");
			ASSERT(0);
		}
	}
#endif
	
	vpo_close(g_vpo_dev);
#ifdef DUAL_VIDEO_OUTPUT
	if(RET_SUCCESS!=vpo_close((struct vpo_device *)dev_get_by_id(HLD_DEV_TYPE_DIS, 1)))
		ASSERT(0);
#endif
    snd_close(g_snd_dev);
	nim_close(g_nim_dev);
	if(g_nim_dev2)
		nim_close(g_nim_dev2);
	if(g_rfm_dev)
		rfm_close(g_rfm_dev);
#if (SYS_MAIN_BOARD == BOARD_M3329E_DEMO01V01 || SYS_MAIN_BOARD == BOARD_DB_M3602_02V01 || SYS_MAIN_BOARD == BOARD_DB_M3602_04V01)
	if(g_scart_dev)
		scart_close(g_scart_dev);
#endif
	led_display_flag = 0;
#if (SYS_MAIN_BOARD == BOARD_S3602_DEMO)
	// Power off
	HAL_GPIO_BIT_DIR_SET(25, HAL_GPIO_O_DIR);
	HAL_GPIO_BIT_SET(25, 0);
#elif (SYS_MAIN_BOARD == BOARD_DB_M3602_02V01 || SYS_MAIN_BOARD == BOARD_DB_M3602_04V01)
	// Power off
/*alfred.wu 不允许ali的power off*/	
/*	
	HAL_GPIO_BIT_DIR_SET(61, HAL_GPIO_O_DIR);
	HAL_GPIO_BIT_SET(61, 1);
	
	// Tuner LNB power off
	HAL_GPIO_BIT_DIR_SET(73, HAL_GPIO_O_DIR);
	HAL_GPIO_BIT_SET(73, 1);
*//*end*/
#endif
}
Example #13
0
bool ImportWAV(wxString fName, WaveTrack **dest1, WaveTrack **dest2, DirManager *dirManager)
{
  *dest1 = 0;
  *dest2 = 0;

  snd_node sndfile;
  snd_node sndbuffer;
  
  sndfile.device = SND_DEVICE_FILE;
  sndfile.write_flag = SND_READ;
  strcpy(sndfile.u.file.filename, (const char *)fName);
  sndfile.u.file.file = 0;
  
  int err;
  long flags=0;
  
  err = snd_open(&sndfile, &flags);
  if (err) return false;
  
  if (sndfile.format.channels < 1 || sndfile.format.channels > 2)
  {
    wxMessageBox("Unknown audio format.");
	  return false;
  }

  *dest1 = new WaveTrack(dirManager);
  wxASSERT(*dest1);
  (*dest1)->rate = sndfile.format.srate;
  if (sndfile.format.channels == 2) {
    *dest2 = new WaveTrack(dirManager);
    wxASSERT(*dest1);
    (*dest2)->rate = sndfile.format.srate;
  }

  sndbuffer.device = SND_DEVICE_MEM;
  sndbuffer.write_flag = SND_WRITE;
  sndbuffer.u.mem.buffer_max = 0;
  sndbuffer.u.mem.buffer = 0;
  sndbuffer.u.mem.buffer_len = 0;
  sndbuffer.u.mem.buffer_pos = 0;
  sndbuffer.format.channels = sndfile.format.channels;
  sndbuffer.format.mode = SND_MODE_PCM; // SND_MODE_FLOAT
  sndbuffer.format.bits = 16;
  sndbuffer.format.srate = sndfile.format.srate;

  int maxblocksize = WaveTrack::GetIdealBlockSize();

  char *srcbuffer = new char[maxblocksize*2];
  char *dstbuffer = new char[maxblocksize*2];
  char *leftbuffer = new char[maxblocksize*2];
  char *rightbuffer = new char[maxblocksize*2];

  long filelen = sndfile.u.file.end_offset - sndfile.u.file.byte_offset;
  long bytescompleted = 0;

  wxProgressDialog *progress = NULL;  
  wxYield();
  wxStartTimer();
  wxBusyCursor busy;

  long block;
  do {
    block = maxblocksize;
    block = snd_read(&sndfile, srcbuffer, block);
    if (block > 0) {
      long b2 = snd_convert(&sndbuffer, dstbuffer,  // to
			    &sndfile, srcbuffer, block);      // from
      if (sndfile.format.channels == 1)
	(*dest1)->Append((sampleType *)dstbuffer, b2);
      else {
	for(int i=0; i<b2; i++) {
	  ((sampleType *)leftbuffer)[i] = ((sampleType *)dstbuffer)[2*i];
	  ((sampleType *)rightbuffer)[i] = ((sampleType *)dstbuffer)[2*i+1];
	}
	(*dest1)->Append((sampleType *)leftbuffer, (sampleCount)b2);
	(*dest2)->Append((sampleType *)rightbuffer, (sampleCount)b2);
      }
      
      bytescompleted += block;
      
    }
    
	if (!progress && wxGetElapsedTime(false) > 500) {
	  progress =
		new wxProgressDialog("Import","Importing audio file",
							 filelen);
	}	
	if (progress) {
	  int progressvalue = (bytescompleted > filelen)? filelen : bytescompleted;
	  progress->Update(progressvalue);
	}
  } while (block > 0);

  snd_close(&sndfile);

  #ifndef __WXMAC__
  if (bytescompleted != filelen) {
	printf("Bytes completed: %d   Expected file len: %d\n",
		   bytescompleted, filelen);
  }
  #endif

  if (progress)
	delete progress;
  
  delete[] srcbuffer;
  delete[] dstbuffer;
  delete[] leftbuffer;
  delete[] rightbuffer;
  
  return true;
}
Example #14
0
int main(int argc, char *argv[])
{
    char *fromfile = NULL;
    char *tofile = NULL;
    int i;
    long flags = 0;
    long frames;
    long len;
    long checksum = 0;
    long count = 0;

    int format = SND_HEAD_AIFF;
    int mode = SND_MODE_PCM;
    int channels = 1;
    int bits = 16;
    double srate = 44100.0;
    snd_node from_snd, to_snd;
    char from_buf[MAXLEN];
    char to_buf[MAXLEN];
    long frames_from_len;
    long frames_to_len;
    long from_len = 0;
    long to_len = 0;

    for (i = 1; i < argc; i++) {
        if (*(argv[i]) != '-') {
            if (!fromfile) fromfile = argv[i];
            else if (!tofile) tofile = argv[i];
            else {
                printf("%s: don't know what to do with 3rd file\n", argv[i]);
                return 1;
            }
        } else {
            char *flag = argv[i] + 1;
            if (*flag == '?') {
                printf("convert -- sound file conversion utility\n\n");
                printf("usage: convert fromfile tofile -flag1 -flag2 ...\n");
                printf("  -fa -- AIFF file format\n");
                printf("  -fi -- IRCAM file format\n");
                printf("  -fn -- NeXT/Sun file format\n");
                printf("  -fw -- Wave file format\n");
                printf("  -ep -- PCM\n");
                printf("  -em -- u-Law\n");
                printf("  -ef -- float\n");
                printf("  -eu -- unsigned PCM\n");
                printf("  -b1 -- 8-bit\n");
                printf("  -b2 -- 16-bit\n");
                printf("  -b4 -- 32-bit\n");
                printf("  -c1 -- 1 channel, etc.\n");
                printf("use 'ada' to get audio input or output\n");
            } else if (*flag == 'f') {
                switch (flag[1]) {
                case 'a':
                    format = SND_HEAD_AIFF;
                    break;
                case 'i':
                    format = SND_HEAD_IRCAM;
                    break;
                case 'n':
                    format = SND_HEAD_NEXT;
                    break;
                case 'w':
                    format = SND_HEAD_WAVE;
                    break;
                default:
                    printf("flag %s ignored\n", argv[i]);
                    break;
                }
            } else if (*flag == 'e') {
                switch (flag[1]) {
                case 'p':
                    mode = SND_MODE_PCM;
                    break;
                case 'm':
                    mode = SND_MODE_ULAW;
                    break;
                case 'f':
                    mode = SND_MODE_FLOAT;
                    break;
                case 'u':
                    mode = SND_MODE_UPCM;
                    break;
                default:
                    printf("flag %s ignored\n", argv[i]);
                    break;
                }
            } else if (*flag == 'b') {
                switch (flag[1]) {
                case '1':
                    bits = 8;
                    break;
                case '2':
                    bits = 16;
                    break;
                case '4':
                    bits = 32;
                    break;
                default:
                    printf("flag %s ignored\n", argv[i]);
                    break;
                }
            } else if (*flag == 'r') {
                switch (flag[1]) {
                case '4':
                    srate = 44100.0;
                    break;
                case '2':
                    srate = 22050.0;
                    break;
                case '1':
                    srate = 11025.0;
                    break;
                case '8':
                    srate = 8000.0;
                    break;
                default:
                    printf("flag %s ignored\n", argv[i]);
                    break;
                }
            } else if (*flag == 'c') {
                channels = atoi(flag+1);
                if (channels < 1 || channels > 16) {
                    channels = 1;
                    printf("flag %s ignored, using 1 channel\n",
                           argv[i]);
                }
            }
        }
    }
    if (!tofile) {
        printf("2 files not found, use -? for help\n");
        return 1;
    }

    from_snd.device = SND_DEVICE_FILE;
    from_snd.write_flag = SND_READ;
    from_snd.u.file.byte_offset = 0;
    from_snd.format.channels = channels;
    from_snd.format.mode = mode;
    from_snd.format.bits = bits;
    from_snd.format.srate = srate;

    if (strcmp(fromfile, "ada") == 0) {
        from_snd.device = SND_DEVICE_AUDIO;
        from_snd.u.audio.protocol = SND_COMPUTEAHEAD;
        from_snd.u.audio.latency = 1.0;
        from_snd.u.audio.granularity = 0.1;
        strcpy(from_snd.u.file.filename, "");
    } else {
        strcpy(from_snd.u.file.filename, fromfile);
    }
    if (snd_open(&from_snd, &flags) != SND_SUCCESS) {
        printf("error opening %s for input\n", fromfile);
        exit(1);
    }
    printf("Opened %s for input: ", from_snd.u.file.filename);
    snd_print_info(&from_snd);

    to_snd.device = SND_DEVICE_FILE;
    to_snd.write_flag = SND_WRITE;
    to_snd.format.channels = channels;
    to_snd.format.mode = mode;
    to_snd.format.bits = bits;
    to_snd.format.srate = from_snd.format.srate;
    to_snd.u.file.header = format;	/* header format, e.g. AIFF */
    if (to_snd.u.file.header == SND_HEAD_WAVE && to_snd.format.mode == SND_MODE_PCM &&
            to_snd.format.bits == 8) to_snd.format.mode = SND_MODE_UPCM;
    if (strcmp(tofile, "ada") == 0) {
        to_snd.device = SND_DEVICE_AUDIO;
        to_snd.u.audio.protocol = SND_COMPUTEAHEAD;
        to_snd.u.audio.latency = 0.0;
        to_snd.u.audio.granularity = 0.1;
        strcpy(to_snd.u.audio.interfacename, "");
        strcpy(to_snd.u.audio.devicename, "");
    } else {
        strcpy(to_snd.u.file.filename, tofile);
    }
    if (snd_open(&to_snd, &flags) != SND_SUCCESS) {
        printf("error opening %s for output\n", tofile);
        exit(1);
    }
    printf("Opened %s for output: ", to_snd.u.file.filename);
    snd_print_info(&to_snd);

    /* figure out how much to convert on each iteration */

    /* first, compute how many frames could fit in each buffer */
    from_len = MAXLEN / snd_bytes_per_frame(&from_snd);
    to_len = MAXLEN / snd_bytes_per_frame(&to_snd);

    /* then compute the minimum of the two frame counts */
    frames = min(from_len, to_len);

    while (1) {
        /* then convert back from frame counts to byte counts: */
        while ((frames_from_len = snd_poll(&from_snd)) <=0);
        frames_from_len = min(frames_from_len, frames);
        while ((frames_to_len = snd_poll(&to_snd)) <= 0);
        frames_to_len = min(frames_to_len, frames);
        len = min(frames_to_len, frames_from_len);
        len = snd_read(&from_snd, from_buf, len);
        if (((from_snd.device == SND_DEVICE_AUDIO) &&
                (count > from_snd.format.srate * 10)) || (!len)) {
            break;
        }
        for (i = 0; i < len * snd_bytes_per_frame(&from_snd); i++) {
            checksum += from_buf[i];
            count++;
        }
        len = snd_convert(&to_snd, to_buf, &from_snd, from_buf, len);
        len = snd_write(&to_snd, to_buf, len);
        printf("#");
        fflush(stdout);
    }
    snd_close(&from_snd);
    if (to_snd.device == SND_DEVICE_AUDIO) {
        while (snd_flush(&to_snd) != SND_SUCCESS) ;
    }
    snd_close(&to_snd);

    printf("Read %ld frames, checksum = %ld\n", count, checksum);
    exit(0);
}