Ejemplo n.º 1
0
AU_Wave *
AU_WaveNew(void)
{
	AU_Wave *w;

	if ((w = AG_TryMalloc(sizeof(AU_Wave))) == NULL) {
		return (NULL);
	}
	w->flags = 0;
	w->file = NULL;
	w->frames = NULL;
	w->nFrames = 0;
	w->ch = 0;
	w->vizFrames = NULL;
	w->nVizFrames = 0;
	w->peak = 0.0;
	memset(&w->info, 0, sizeof(w->info));
	AG_MutexInitRecursive(&w->lock);
	return (w);
}
Ejemplo n.º 2
0
/* Generate a reduced waveform for visualization purposes. */
int
AU_WaveGenVisual(AU_Wave *w, int reduce)
{
	int i, j, ch;
	float *pIn, *pViz;

	if (reduce <= 0) {
		AG_SetError("Reduction factor <= 0");
		return (-1);
	}
	if (w->vizFrames != NULL) {
		Free(w->vizFrames);
		w->nVizFrames = 0;
	}

	sf_command(w->file, SFC_CALC_SIGNAL_MAX, &w->peak, sizeof(w->peak));
	w->nVizFrames = w->nFrames/reduce;
	if ((w->vizFrames = AG_TryMalloc(w->nVizFrames*sizeof(float))) == NULL) {
		w->nVizFrames = 0;
		return (-1);
	}

	pViz = &w->vizFrames[0];
	for (i = 0; i < w->nVizFrames; i++) {
		for (ch = 0; ch < w->ch; ch++)
			*pViz++ = 0.0;
	}
	pIn = &w->frames[0];
	pViz = &w->vizFrames[0];
	for (i = 0; i < w->nVizFrames; i++) {
		for (j = 0; j < reduce; j++) {
			for (ch = 0; ch < w->ch; ch++) {
				pViz[ch] += MAX(w->vizFrames[i],
				    fabs((*pIn++)/w->peak));
			}
		}
		for (ch = 0; ch < w->ch; ch++)
			*pViz++ /= reduce;
	}
	return (0);
}
Ejemplo n.º 3
0
/* Load audio stream from a file. */
int
AU_WaveLoad(AU_Wave *w, const char *path)
{
	sf_count_t nReadFrames = 0;

	if (w->file != NULL) {
		sf_close(w->file);
		AU_WaveFreeData(w);
	}

	/*
	 * Read the raw audio data.
	 */
	memset(&w->info, 0, sizeof(w->info));
	w->file = sf_open(path, SFM_READ, &w->info);
	if (w->file == NULL) {
		AG_SetError("%s: sf_open() failed", path);
		return (-1);
	}
	w->nFrames = w->info.frames;
	w->ch = w->info.channels;

	if ((w->frames = AG_TryMalloc(w->nFrames*w->ch*sizeof(float))) == NULL) {
		goto fail;
	}
	nReadFrames = 0;
	while (nReadFrames < w->nFrames) {
		sf_count_t rv;

		rv = sf_readf_float(w->file, &w->frames[nReadFrames], 4096);
		if (rv == 0) {
			break;
		}
		nReadFrames += rv;
	}
	return (0);
fail:
	AU_WaveFreeData(w);
	return (-1);
}
Ejemplo n.º 4
0
static int
SDLGL_OpenVideo(void *obj, Uint w, Uint h, int depth, Uint flags)
{
	char buf[16];
	AG_Driver *drv = obj;
	AG_DriverSw *dsw = obj;
	AG_DriverSDLGL *sgl = obj;
	Uint32 sFlags = SDL_OPENGL;
	int newDepth;

	/* Set the requested display options. */
	if (flags & AG_VIDEO_RESIZABLE) { sFlags |= SDL_RESIZABLE; }
	if (flags & AG_VIDEO_ANYFORMAT) { sFlags |= SDL_ANYFORMAT; }
	if (flags & AG_VIDEO_HWPALETTE) { sFlags |= SDL_HWPALETTE; }
	if (flags & AG_VIDEO_DOUBLEBUF) { sFlags |= SDL_DOUBLEBUF; }
	if (flags & AG_VIDEO_FULLSCREEN) { sFlags |= SDL_FULLSCREEN; }
	if (flags & AG_VIDEO_NOFRAME) { sFlags |= SDL_NOFRAME; }
	
	if (flags & AG_VIDEO_OVERLAY)
		dsw->flags |= AG_DRIVER_SW_OVERLAY;
	if (flags & AG_VIDEO_BGPOPUPMENU)
		dsw->flags |= AG_DRIVER_SW_BGPOPUP;

	/* Apply the output capture settings. */
	if (AG_Defined(drv, "out")) {
		char *ext;

		AG_GetString(drv, "out", buf, sizeof(buf));
		if ((ext = strrchr(buf, '.')) != NULL &&
		    ext[1] != '\0') {
			if (Strcasecmp(&ext[1], "jpeg") == 0 ||
			    Strcasecmp(&ext[1], "jpg") == 0) {
				sgl->outMode = AG_SDLGL_OUT_JPEG;
				if ((sgl->outPath = TryStrdup(buf)) == NULL)
					return (-1);
			} else if (Strcasecmp(&ext[1], "png") == 0) {
				sgl->outMode = AG_SDLGL_OUT_PNG;
				if ((sgl->outPath = TryStrdup(buf)) == NULL)
					return (-1);
			} else {
				AG_SetError("Invalid out= argument: `%s'", buf);
				return (-1);
			}
			if (AG_Defined(drv, "outFirst")) {
				AG_GetString(drv, "outFirst", buf, sizeof(buf));
				sgl->outFrame = atoi(buf);
			} else {
				sgl->outFrame = 0;
			}
			if (AG_Defined(drv, "outLast")) {
				AG_GetString(drv, "outLast", buf, sizeof(buf));
				sgl->outLast = atoi(buf);
			}
		}
	}
	
	/* Apply the default resolution settings. */
	if (w == 0 && AG_Defined(drv, "width")) {
		AG_GetString(drv, "width", buf, sizeof(buf));
		w = atoi(buf);
	}
	if (h == 0 && AG_Defined(drv, "height")) {
		AG_GetString(drv, "height", buf, sizeof(buf));
		h = atoi(buf);
	}
	if (depth == 0 && AG_Defined(drv, "depth")) {
		AG_GetString(drv, "depth", buf, sizeof(buf));
		depth = atoi(buf);
	}

	/* Set the video mode. Force hardware palette in 8bpp. */
	Verbose(_("SDLGL: Setting mode %dx%d (%d bpp)\n"), w, h, depth);
	newDepth = SDL_VideoModeOK(w, h, depth, sFlags);
	if (newDepth == 8) {
		Verbose(_("Enabling hardware palette"));
		sFlags |= SDL_HWPALETTE;
	}
	if ((sgl->s = SDL_SetVideoMode((int)w, (int)h, newDepth, sFlags))
	    == NULL) {
		AG_SetError("Setting %dx%dx%d mode: %s", w, h, newDepth,
		    SDL_GetError());
		return (-1);
	}
	SDL_EnableUNICODE(1);

	if ((drv->videoFmt = AG_SDL_GetPixelFormat(sgl->s)) == NULL) {
		goto fail;
	}
	dsw->w = sgl->s->w;
	dsw->h = sgl->s->h;
	dsw->depth = (Uint)drv->videoFmt->BitsPerPixel;

	Verbose(_("SDLGL: New display (%dbpp)\n"),
	     (int)drv->videoFmt->BitsPerPixel);
	
	/* Initialize clipping rectangles. */
	if (InitClipRects(sgl, dsw->w, dsw->h) == -1)
		goto fail;
	
	/* Create the cursors. */
	if (AG_SDL_InitDefaultCursor(sgl) == -1 ||
	    AG_InitStockCursors(drv) == -1)
		goto fail;

	/* Initialize the GL viewport. */
	AG_GL_InitContext(
	    AG_RECT(0, 0, AGDRIVER_SW(sgl)->w, AGDRIVER_SW(sgl)->h));

	if (!(dsw->flags & AG_DRIVER_SW_OVERLAY)) {
		ClearBackground();
	}

	/* Initialize the output capture buffer. */
	Free(sgl->outBuf);
	if ((sgl->outBuf = AG_TryMalloc(dsw->w*dsw->h*4)) == NULL) {
		AG_Verbose("Out of memory for buffer; disabling capture\n");
		sgl->outMode = AG_SDLGL_OUT_NONE;
	}

	/* Toggle fullscreen if requested. */
	if (AG_CfgBool("view.full-screen")) {
		if (!SDL_WM_ToggleFullScreen(sgl->s))
			AG_SetCfgBool("view.full-screen", 0);
	}
	return (0);
fail:
	if (drv->videoFmt) {
		AG_PixelFormatFree(drv->videoFmt);
		drv->videoFmt = NULL;
	}
	return (-1);
}