示例#1
0
int _al_show_native_message_box(ALLEGRO_DISPLAY *display,
   ALLEGRO_NATIVE_DIALOG *fd)
{
   UINT type = 0;
   int result;

   uint16_t *wide_text, *wide_title;
   size_t text_len, title_len;

   /* Note: the message box code cannot assume that Allegro is installed. */

   if (fd->flags & ALLEGRO_MESSAGEBOX_QUESTION)
      type |= MB_ICONQUESTION;
   else if (fd->flags & ALLEGRO_MESSAGEBOX_WARN)
      type |= MB_ICONWARNING;
   else if (fd->flags & ALLEGRO_MESSAGEBOX_ERROR) 
      type |= MB_ICONERROR;
   else 
      type |= MB_ICONINFORMATION;

   if (fd->flags & ALLEGRO_MESSAGEBOX_YES_NO)
      type |= MB_YESNO;
   else if (fd->flags & ALLEGRO_MESSAGEBOX_OK_CANCEL)
      type |= MB_OKCANCEL;

   /* heading + text are combined together */

   if (al_ustr_size(fd->mb_heading)) 
      al_ustr_append_cstr(fd->mb_heading, "\n\n");

   al_ustr_append(fd->mb_heading, fd->mb_text);

   text_len = al_ustr_size_utf16(fd->mb_heading);
   title_len = al_ustr_size_utf16(fd->title);

   wide_text = al_malloc(text_len + 1);
   if (!wide_text)
      return 0;

   wide_title = al_malloc(title_len + 1);
   if (!wide_title) {
      al_free(wide_text);
      return 0;
   }

   al_ustr_encode_utf16(fd->mb_heading, wide_text, text_len);
   al_ustr_encode_utf16(fd->title, wide_title, title_len);

   result = MessageBoxW(al_get_win_window_handle(display),
      (LPCWSTR) wide_text, (LPCWSTR) wide_title, type);

   al_free(wide_text);
   al_free(wide_title);

   if (result == IDYES || result == IDOK)
      return 1;
   else
      return 0;
}
/* Function: al_open_memfile
 */
ALLEGRO_FILE *al_open_memfile(void *mem, int64_t size, const char *mode)
{
   ALLEGRO_FILE *memfile;
   ALLEGRO_FILE_MEMFILE *userdata = NULL;

   ASSERT(mem);
   ASSERT(size > 0);
   
   userdata = al_malloc(sizeof(ALLEGRO_FILE_MEMFILE));
   if (!userdata) {
      al_set_errno(ENOMEM);
      return NULL;
   }
   
   memset(userdata, 0, sizeof(*userdata));
   userdata->size = size;
   userdata->pos = 0;
   userdata->mem = mem;
   
   userdata->readable = strchr(mode, 'r') || strchr(mode, 'R');
   userdata->writable = strchr(mode, 'w') || strchr(mode, 'W');
      
   memfile = al_create_file_handle(&memfile_vtable, userdata);
   if (!memfile) {
      al_free(userdata);
   }

   return memfile;
}
示例#3
0
/* get_bitmap_info:
 *  Returns a BITMAPINFO structure suited to an ALLEGRO_BITMAP.
 *  You have to free the memory allocated by this function.
 *
 *  This version always returns a 32-bit BITMAPINFO.
 */
static BITMAPINFO *get_bitmap_info(ALLEGRO_BITMAP *bitmap)
{
   BITMAPINFO *bi;
   int i;

   bi = (BITMAPINFO *) al_malloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 256);

   ZeroMemory(&bi->bmiHeader, sizeof(BITMAPINFOHEADER));

   bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   bi->bmiHeader.biBitCount = 32;
   bi->bmiHeader.biPlanes = 1;
   bi->bmiHeader.biWidth = al_get_bitmap_width(bitmap);
   bi->bmiHeader.biHeight = -al_get_bitmap_height(bitmap);
   bi->bmiHeader.biClrUsed = 256;
   bi->bmiHeader.biCompression = BI_RGB;

   for (i = 0; i < 256; i++) {
      bi->bmiColors[i].rgbRed = 0;
      bi->bmiColors[i].rgbGreen = 0;
      bi->bmiColors[i].rgbBlue = 0;
      bi->bmiColors[i].rgbReserved = 0;
   }

   return bi;
}
示例#4
0
static void *file_stdio_fopen(const char *path, const char *mode)
{
   FILE *fp;
   USERDATA *userdata;

   ALLEGRO_DEBUG("opening %s %s\n", path, mode);

#ifdef ALLEGRO_WINDOWS
   {
      wchar_t *wpath = _al_win_utf8_to_utf16(path);
      wchar_t *wmode = _al_win_utf8_to_utf16(mode);
      fp = _wfopen(wpath, wmode);
      al_free(wpath);
      al_free(wmode);
   }
#else
   fp = fopen(path, mode);
#endif

   if (!fp) {
      al_set_errno(errno);
      return NULL;
   }

   userdata = al_malloc(sizeof(USERDATA));
   if (!userdata) {
      fclose(fp);
      return NULL;
   }

   userdata->fp = fp;
   userdata->errnum = 0;

   return userdata;
}
示例#5
0
static void ogl_unlock_region_nonbb_fbo_writeonly(ALLEGRO_BITMAP *bitmap,
   ALLEGRO_BITMAP_EXTRA_OPENGL *ogl_bitmap, int gl_y, int orig_format)
{
   const int lock_format = bitmap->locked_region.format;
   const int orig_pixel_size = al_get_pixel_size(orig_format);
   const int dst_pitch = bitmap->lock_w * orig_pixel_size;
   unsigned char * const tmpbuf = al_malloc(dst_pitch * bitmap->lock_h);
   GLenum e;

   _al_convert_bitmap_data(
      ogl_bitmap->lock_buffer,
      bitmap->locked_region.format,
      -bitmap->locked_region.pitch,
      tmpbuf,
      orig_format,
      dst_pitch,
      0, 0, 0, 0,
      bitmap->lock_w, bitmap->lock_h);

   glTexSubImage2D(GL_TEXTURE_2D, 0,
      bitmap->lock_x, gl_y,
      bitmap->lock_w, bitmap->lock_h,
      get_glformat(orig_format, 2),
      get_glformat(orig_format, 1),
      tmpbuf);
   e = glGetError();
   if (e) {
      ALLEGRO_ERROR("glTexSubImage2D for format %d failed (%s).\n",
         lock_format, _al_gl_error_string(e));
   }

   al_free(tmpbuf);
}
示例#6
0
static bool fill_joystick_buttons(ALLEGRO_JOYSTICK_LINUX *joy, int fd)
{
    unsigned long key_bits[NLONGS(KEY_CNT)] = {0};
    int b;
    int i;

    if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)), key_bits) < 0)
        return false;

    b = 0;

    for (i = LJOY_BTN_RANGE_START; i < LJOY_BTN_RANGE_END; i++) {
        if (TEST_BIT(i, key_bits) && is_joystick_button(i)) {
            joy->button_mapping[b].ev_code = i;
            ALLEGRO_DEBUG("Input event code %d maps to button %d\n", i, b);

            joy->parent.info.button[b].name = al_malloc(32);
            snprintf((char *)joy->parent.info.button[b].name, 32, "B%d", b+1);

            b++;
            if (b == _AL_MAX_JOYSTICK_BUTTONS)
                break;
        }
    }

    joy->parent.info.num_buttons = b;

    /* Clear the rest. */
    for (; b < _AL_MAX_JOYSTICK_BUTTONS; b++) {
        joy->button_mapping[b].ev_code = -1;
    }

    return true;
}
示例#7
0
/* Function: al_create_event_queue
 */
ALLEGRO_EVENT_QUEUE *al_create_event_queue(void)
{
   ALLEGRO_EVENT_QUEUE *queue = al_malloc(sizeof *queue);

   ASSERT(queue);

   if (queue) {
      _al_vector_init(&queue->sources, sizeof(ALLEGRO_EVENT_SOURCE *));

      _al_vector_init(&queue->events, sizeof(ALLEGRO_EVENT));
      _al_vector_alloc_back(&queue->events);
      queue->events_head = 0;
      queue->events_tail = 0;
      queue->paused = false;

      _AL_MARK_MUTEX_UNINITED(queue->mutex);
      _al_mutex_init(&queue->mutex);
      _al_cond_init(&queue->cond);

      _al_register_destructor(_al_dtor_list, "queue", queue,
         (void (*)(void *)) al_destroy_event_queue);
   }

   return queue;
}
示例#8
0
/* Function: al_fopen_fd
 */
ALLEGRO_FILE *al_fopen_fd(int fd, const char *mode)
{
   ALLEGRO_FILE *f;
   USERDATA *userdata;
   FILE *fp;

   userdata = al_malloc(sizeof(USERDATA));
   if (!userdata)
      return NULL;

   /* The fd should remain open if this function fails in any way,
    * so delay the fdopen() call to last.
    */
   userdata->fp = NULL;
   userdata->errnum = 0;

   f = al_create_file_handle(&_al_file_interface_stdio, userdata);
   if (!f) {
      al_free(userdata);
      return NULL;
   }

   fp = fdopen(fd, mode);
   if (!fp) {
      al_set_errno(errno);
      al_fclose(f);
      return NULL;
   }

   userdata->fp = fp;
   return f;
}
示例#9
0
/* Creates a memory bitmap.
 */
static ALLEGRO_BITMAP *_al_create_memory_bitmap(int w, int h)
{
   ALLEGRO_BITMAP *bitmap;
   int pitch;
   int format = al_get_new_bitmap_format();

   format = _al_get_real_pixel_format(al_get_current_display(), format);

   bitmap = al_calloc(1, sizeof *bitmap);
   bitmap->size = sizeof(*bitmap);

   pitch = w * al_get_pixel_size(format);

   bitmap->vt = NULL;
   bitmap->format = format;
   bitmap->flags = (al_get_new_bitmap_flags() | ALLEGRO_MEMORY_BITMAP) &
      ~ALLEGRO_VIDEO_BITMAP;
   bitmap->w = w;
   bitmap->h = h;
   bitmap->pitch = pitch;
   bitmap->display = NULL;
   bitmap->locked = false;
   bitmap->cl = bitmap->ct = 0;
   bitmap->cr_excl = w;
   bitmap->cb_excl = h;
   al_identity_transform(&bitmap->transform);
   bitmap->parent = NULL;
   bitmap->xofs = bitmap->yofs = 0;
   bitmap->memory = al_malloc(pitch * h);
   bitmap->preserve_texture = !(al_get_new_bitmap_flags() & ALLEGRO_NO_PRESERVE_TEXTURE);
   return bitmap;
}
static void *file_phys_fopen(const char *filename, const char *mode)
{
   PHYSFS_file *phys;
   ALLEGRO_FILE_PHYSFS *fp;

   /* XXX handle '+' modes */
   /* It might be worth adding a function to parse mode strings, to be
    * shared amongst these kinds of addons.
    */
   if (streq(mode, "r") || streq(mode, "rb"))
      phys = PHYSFS_openRead(filename);
   else if (streq(mode, "w") || streq(mode, "wb"))
      phys = PHYSFS_openWrite(filename);
   else if (streq(mode, "a") || streq(mode, "ab"))
      phys = PHYSFS_openAppend(filename);
   else
      phys = NULL;

   if (!phys) {
      phys_set_errno(NULL);
      return NULL;
   }

   fp = al_malloc(sizeof(*fp));
   if (!fp) {
      al_set_errno(ENOMEM);
      PHYSFS_close(phys);
      return NULL;
   }

   fp->phys = phys;
   fp->error_indicator = false;

   return fp;
}
示例#11
0
static bool raspberrypi_set_mouse_cursor(ALLEGRO_DISPLAY *display, ALLEGRO_MOUSE_CURSOR *cursor)
{
    ALLEGRO_DISPLAY_RASPBERRYPI *d = (void *)display;
    ALLEGRO_MOUSE_CURSOR_RASPBERRYPI *pi_cursor = (void *)cursor;
    int w = al_get_bitmap_width(pi_cursor->bitmap);
    int h = al_get_bitmap_height(pi_cursor->bitmap);
    int pitch = w * sizeof(uint32_t);
    uint32_t *data = al_malloc(pitch * h);
    ALLEGRO_LOCKED_REGION *lr = al_lock_bitmap(pi_cursor->bitmap, ALLEGRO_PIXEL_FORMAT_ARGB_8888, ALLEGRO_LOCK_READONLY);
    int y;
    for (y = 0; y < h; y++) {
        uint8_t *p = (uint8_t *)lr->data + lr->pitch * y;
        uint8_t *p2 = (uint8_t *)data + pitch * y;
        memcpy(p2, p, pitch);
    }
    al_unlock_bitmap(pi_cursor->bitmap);
    delete_cursor_data(d);
    set_cursor_data(d, data, w, h);
    al_free(data);
    if (cursor_added) {
        hide_cursor(d);
        show_cursor(d);
    }
    return true;
}
示例#12
0
static void ogl_lock_region_nonbb_readwrite_fbo(
   ALLEGRO_BITMAP *bitmap, ALLEGRO_BITMAP_EXTRA_OPENGL *ogl_bitmap,
   int x, int gl_y, int w, int h, int format)
{
   const int pixel_size = al_get_pixel_size(format);
   const int pitch = ogl_pitch(w, pixel_size);
   GLint old_fbo;
   GLenum e;

   glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &old_fbo);

   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ogl_bitmap->fbo_info->fbo);

   ogl_bitmap->lock_buffer = al_malloc(pitch * h);

   glReadPixels(x, gl_y, w, h,
      get_glformat(format, 2),
      get_glformat(format, 1),
      ogl_bitmap->lock_buffer);

   e = glGetError();
   if (e) {
      ALLEGRO_ERROR("glReadPixels for format %s failed (%s).\n",
         _al_format_name(format), _al_gl_error_string(e));
   }

   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, old_fbo);

   bitmap->locked_region.data = ogl_bitmap->lock_buffer + pitch * (h - 1);
   bitmap->locked_region.format = format;
   bitmap->locked_region.pitch = -pitch;
   bitmap->locked_region.pixel_size = pixel_size;
}
示例#13
0
static void ogl_lock_region_nonbb_readwrite_nonfbo(
   ALLEGRO_BITMAP *bitmap, ALLEGRO_BITMAP_EXTRA_OPENGL *ogl_bitmap,
   int x, int gl_y, int w, int h, int format)
{
   /* No FBO - fallback to reading the entire texture */
   const int pixel_size = al_get_pixel_size(format);
   const int pitch = ogl_pitch(ogl_bitmap->true_w, pixel_size);
   GLenum e;
   (void) w;

   ogl_bitmap->lock_buffer = al_malloc(pitch * ogl_bitmap->true_h);

   glBindTexture(GL_TEXTURE_2D, ogl_bitmap->texture);
   glGetTexImage(GL_TEXTURE_2D, 0,
      get_glformat(format, 2),
      get_glformat(format, 1),
      ogl_bitmap->lock_buffer);

   e = glGetError();
   if (e) {
      ALLEGRO_ERROR("glGetTexImage for format %s failed (%s).\n",
         _al_format_name(format), _al_gl_error_string(e));
   }

   bitmap->locked_region.data = ogl_bitmap->lock_buffer +
      pitch * (gl_y + h - 1) + pixel_size * x;
   bitmap->locked_region.format = format;
   bitmap->locked_region.pitch = -pitch;
   bitmap->locked_region.pixel_size = pixel_size;
}
示例#14
0
static bool select_folder(ALLEGRO_DISPLAY_WIN *win_display,
   ALLEGRO_NATIVE_DIALOG *fd)
{
   BROWSEINFO folderinfo;
   LPCITEMIDLIST pidl;
   char buf[MAX_PATH] = "";
   char dbuf[MAX_PATH] = "";

   folderinfo.hwndOwner = win_display->window;
   folderinfo.pidlRoot = NULL;
   folderinfo.pszDisplayName = dbuf;
   folderinfo.lpszTitle = al_cstr(fd->title);
   folderinfo.ulFlags = 0;
   folderinfo.lpfn = NULL;

   pidl = SHBrowseForFolder(&folderinfo);
   if (pidl) {
      SHGetPathFromIDList(pidl, buf);
      fd->fc_path_count = 1;
      fd->fc_paths = al_malloc(sizeof(void *));
      fd->fc_paths[0] = al_create_path(buf);
      return true;
   }
   return false;
}
示例#15
0
static bool ogl_lock_region_backbuffer(
   ALLEGRO_BITMAP *bitmap, ALLEGRO_BITMAP_EXTRA_OPENGL *ogl_bitmap,
   int x, int gl_y, int w, int h, int format, int flags)
{
   const int pixel_size = al_get_pixel_size(format);
   const int pitch = ogl_pitch(w, pixel_size);
   GLenum e;

   ogl_bitmap->lock_buffer = al_malloc(pitch * h);
   if (ogl_bitmap->lock_buffer == NULL) {
      return false;
   }

   if (!(flags & ALLEGRO_LOCK_WRITEONLY)) {
      glReadPixels(x, gl_y, w, h,
         get_glformat(format, 2),
         get_glformat(format, 1),
         ogl_bitmap->lock_buffer);
      e = glGetError();
      if (e) {
         ALLEGRO_ERROR("glReadPixels for format %s failed (%s).\n",
            _al_pixel_format_name(format), _al_gl_error_string(e));
         al_free(ogl_bitmap->lock_buffer);
         ogl_bitmap->lock_buffer = NULL;
         return false;
      }
   }

   bitmap->locked_region.data = ogl_bitmap->lock_buffer + pitch * (h - 1);
   bitmap->locked_region.format = format;
   bitmap->locked_region.pitch = -pitch;
   bitmap->locked_region.pixel_size = pixel_size;
   return true;
}
示例#16
0
static ALLEGRO_SAMPLE *create_sample_s16(int freq, int len)
{
   char *buf = al_malloc(freq * len * sizeof(int16_t));

   return al_create_sample(buf, len, freq, ALLEGRO_AUDIO_DEPTH_INT16,
			   ALLEGRO_CHANNEL_CONF_1, true);
}
示例#17
0
文件: tiled.c 项目: hiltonm/nostos
static inline float * get_float_points (xmlNode *node, const char *name, int *num_points)
{
    assert (node);
    assert (name);
    assert (num_points);

    char *attr = get_xml_attribute (node, name);

    if (attr) {
        int i = 0;
        float *points = NULL;
        LIST *nums_str = split (attr, " ,");

        if (!_al_list_is_empty (nums_str)) {
            *num_points = _al_list_size (nums_str) / 2;
            points = al_malloc (*num_points * 2 * sizeof (float));

            LIST_ITEM *item = _al_list_front (nums_str);
            while (item) {
                points[i++] = atof ((char *)_al_list_item_data (item));
                item = _al_list_next (nums_str, item);
            }
        }
        _al_list_destroy (nums_str);
        return points;
    }

    return NULL;
}
示例#18
0
int t3f_animation_add_frame(T3F_ANIMATION * ap, int bitmap, float x, float y, float z, float w, float h, float angle, int ticks, int flags)
{
	ap->frame[ap->frames] = al_malloc(sizeof(T3F_ANIMATION_FRAME));
	if(ap->frame[ap->frames])
	{
		ap->frame[ap->frames]->bitmap = bitmap;
		ap->frame[ap->frames]->x = x;
		ap->frame[ap->frames]->y = y;
		ap->frame[ap->frames]->z = z;
		if(w < 0.0)
		{
			ap->frame[ap->frames]->width = al_get_bitmap_width(ap->bitmaps->bitmap[bitmap]);
		}
		else
		{
			ap->frame[ap->frames]->width = w;
		}
		if(h < 0.0)
		{
			ap->frame[ap->frames]->height = al_get_bitmap_height(ap->bitmaps->bitmap[bitmap]);
		}
		else
		{
			ap->frame[ap->frames]->height = h;
		}
		ap->frame[ap->frames]->angle = angle;
		ap->frame[ap->frames]->ticks = ticks;
		ap->frame[ap->frames]->flags = flags;
		ap->frames++;
		t3f_animation_build_frame_list(ap);
		return 1;
	}
	return 0;
}
示例#19
0
AlError algl_framebuffer_init(AlGlFramebuffer **result)
{
	BEGIN()

	AlGlFramebuffer *framebuffer = NULL;
	TRY(al_malloc(&framebuffer, sizeof(AlGlFramebuffer)));

	framebuffer->id = 0;
	framebuffer->colourTex = 0;

	glGenFramebuffers(1, &framebuffer->id);

	glGenTextures(1, &framebuffer->colourTex);
	if (framebuffer->colourTex == 0) {
		THROW(AL_ERROR_GENERIC)
	}

	glBindTexture(GL_TEXTURE_2D, framebuffer->colourTex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

	glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->id);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebuffer->colourTex, 0);

	GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
	if (status != GL_FRAMEBUFFER_COMPLETE) {
		al_log_error("Error creating framebuffer: %d", status);
		THROW(AL_ERROR_GENERIC)
	}
ALLEGRO_MOUSE_CURSOR *_al_xwin_create_mouse_cursor(ALLEGRO_BITMAP *bmp,
   int x_focus, int y_focus)
{
   ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();
   Display *xdisplay = system->x11display;

   int bmp_w;
   int bmp_h;
   ALLEGRO_MOUSE_CURSOR_XGLX *xcursor;
   XcursorImage *image;
   int c, ix, iy;
   bool was_locked;

   bmp_w = al_get_bitmap_width(bmp);
   bmp_h = al_get_bitmap_height(bmp);

   xcursor = al_malloc(sizeof *xcursor);
   if (!xcursor) {
      return NULL;
   }

   image = XcursorImageCreate(bmp->w, bmp->h);
   if (image == None) {
      al_free(xcursor);
      return NULL;
   }

   was_locked = al_is_bitmap_locked(bmp);
   if (!was_locked) {
      al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
   }

   c = 0;
   for (iy = 0; iy < bmp_h; iy++) {
      for (ix = 0; ix < bmp_w; ix++) {
         ALLEGRO_COLOR col;
         unsigned char r, g, b, a;

         col = al_get_pixel(bmp, ix, iy);
         al_unmap_rgba(col, &r, &g, &b, &a);
         image->pixels[c++] = (a<<24) | (r<<16) | (g<<8) | (b);
      }
   }

   if (!was_locked) {
      al_unlock_bitmap(bmp);
   }

   image->xhot = x_focus;
   image->yhot = y_focus;

   _al_mutex_lock(&system->lock);
   xcursor->cursor = XcursorImageLoadCursor(xdisplay, image);
   _al_mutex_unlock(&system->lock);

   XcursorImageDestroy(image);

   return (ALLEGRO_MOUSE_CURSOR *)xcursor;
}
示例#21
0
/* Function: al_create_cond
 */
ALLEGRO_COND *al_create_cond(void)
{
   ALLEGRO_COND *cond = al_malloc(sizeof(*cond));
   if (cond) {
      _al_cond_init(&cond->cond);
   }
   return cond;
}
示例#22
0
static thread_local_state* pthreads_thread_init(void)
{
   /* Allocate and copy the 'template' object */
   thread_local_state* ptr = (thread_local_state*)al_malloc(sizeof(thread_local_state));
   memcpy(ptr, &_tls, sizeof(thread_local_state));
   pthread_setspecific(tls_key, ptr);
   return ptr;
}
示例#23
0
static int pulseaudio_allocate_voice(ALLEGRO_VOICE *voice)
{
   PULSEAUDIO_VOICE *pv = al_malloc(sizeof(PULSEAUDIO_VOICE));
   pa_sample_spec ss;
   pa_buffer_attr ba;

   ss.channels = al_get_channel_count(voice->chan_conf);
   ss.rate = voice->frequency;

   if (voice->depth == ALLEGRO_AUDIO_DEPTH_UINT8)
      ss.format = PA_SAMPLE_U8;
   else if (voice->depth == ALLEGRO_AUDIO_DEPTH_INT16)
      ss.format = PA_SAMPLE_S16NE;
#if PA_API_VERSION > 11
   else if (voice->depth == ALLEGRO_AUDIO_DEPTH_INT24)
      ss.format = PA_SAMPLE_S24NE;
#endif
   else if (voice->depth == ALLEGRO_AUDIO_DEPTH_FLOAT32)
      ss.format = PA_SAMPLE_FLOAT32NE;
   else {
      ALLEGRO_ERROR("Unsupported PulseAudio sound format.\n");
      al_free(pv);
      return 1;
   }

   ba.maxlength = 0x10000; // maximum length of buffer
   ba.tlength   = 0x2000;  // target length of buffer
   ba.prebuf    = 0;       // minimum data size required before playback starts
   ba.minreq    = 0;       // minimum size of request 
   ba.fragsize  = -1;      // fragment size (recording)

   pv->s = pa_simple_new(NULL,         // Use the default server.
                   al_get_app_name(),     
                   PA_STREAM_PLAYBACK,
                   NULL,               // Use the default device.
                   "Allegro Voice",    
                   &ss,                
                   NULL,               // Use default channel map
                   &ba,                
                   NULL                // Ignore error code.
   );

   if (!pv->s) {
      al_free(pv);
      return 1;
   }

   voice->extra = pv;

   pv->frame_size = ss.channels * al_get_audio_depth_size(voice->depth);
   pv->status = PV_STOPPED;
   pv->buffer_mutex = al_create_mutex();

   pv->poll_thread = al_create_thread(pulseaudio_update, (void*)voice);
   al_start_thread(pv->poll_thread);

   return 0;
}
示例#24
0
static char *fs_apk_get_current_directory(void)
{
   size_t size = strlen(fs_apk_cwd) + 1;
   char *s = al_malloc(size);
   if (s) {
      memcpy(s, fs_apk_cwd, size);
   }
   return s;
}
示例#25
0
/* Function: al_create_mutex_recursive
 */
ALLEGRO_MUTEX *al_create_mutex_recursive(void)
{
   ALLEGRO_MUTEX *mutex = al_malloc(sizeof(*mutex));
   if (mutex) {
      _AL_MARK_MUTEX_UNINITED(mutex->mutex);
      _al_mutex_init_recursive(&mutex->mutex);
   }
   return mutex;
}
/* Internal function: _al_init_destructors
 *  Initialise a list of destructors.
 */
_AL_DTOR_LIST *_al_init_destructors(void)
{
   _AL_DTOR_LIST *dtors = al_malloc(sizeof(*dtors));

   _AL_MARK_MUTEX_UNINITED(dtors->mutex);
   _al_mutex_init(&dtors->mutex);
   _al_vector_init(&dtors->dtors, sizeof(DTOR));

   return dtors;
}
示例#27
0
void *
xmalloc (size_t n)
{
  if (n == 0) return NULL;

  void *ptr = al_malloc (n);
  if (! ptr)
    error (-1, 0, "%s (%u): cannot allocate memory", __func__,
           (unsigned int) n);
  return ptr;
}
示例#28
0
		void VertexArray::initialize(int64_t vertices_count)
		{
			if (vertices_count < 0) vertices_count = 0;

			if (vertices_count > 0)
				ary = (ALLEGRO_VERTEX*)al_malloc(sizeof(ALLEGRO_VERTEX) * vertices_count);
			else
				ary = nullptr;

			ary_len = vertices_count;
		}
示例#29
0
/* [user thread] */
static void *create_args(void)
{
   ARGS *args = al_malloc(sizeof(*args));
   if (args) {
      args->mutex = al_create_mutex();
      args->cond = al_create_cond();
      args->done = false;
      args->response = true;
   }
   return args;
}
示例#30
0
/* memory management */
T3F_ANIMATION * t3f_create_animation(void)
{
	T3F_ANIMATION * ap;

	ap = al_malloc(sizeof(T3F_ANIMATION));
	if(ap)
	{
		ap->bitmaps = al_malloc(sizeof(T3F_ANIMATION_BITMAPS));
		if(!ap->bitmaps)
		{
			free(ap);
			return NULL;
		}
		ap->bitmaps->count = 0;
		ap->frames = 0;
		ap->frame_list_total = 0;
		ap->flags = 0;
	}
	return ap;
}