/*Calls through createConverter */ UConverter* ucnv_open (const char *name, UErrorCode * err) { if (U_FAILURE (*err)) return NULL; /*In case "name" is NULL we want to open the default converter */ if (name != NULL) return createConverter (name, err); else return createConverter (iconv_getDefaultCodepage(), err); }
static void finishClass(void) { SYMBOL *self = makeID(sc_localstatic, &stdpointer, NULL, "$self"); HASHREC *lst; if (lambdas->captureThis && lambdas->next) { SYMBOL *parent = makeID(sc_member, &stdpointer, NULL, "$parent"); lambda_insert(parent, lambdas); } self->label = nextLabel++; insert(self, lambdas->cls->tp->syms); insertInitSym(self); createConstructorsForLambda(lambdas->cls); insertFunc(lambdas->cls, lambdas->func); createConverter(self); if (!lambdas->isMutable) { TYPE *tp2 = Alloc(sizeof(TYPE)); tp2->type = bt_const; tp2->size = lambdas->func->tp->size; tp2->btp = lambdas->func->tp; lambdas->func->tp = tp2; } createCaller(); }
bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize) { if (handle == nullptr) return false; JUCE_ALSA_LOG ("ALSADevice::setParameters(" << deviceID << ", " << (int) sampleRate << ", " << numChannels << ", " << bufferSize << ")"); snd_pcm_hw_params_t* hwParams; snd_pcm_hw_params_alloca (&hwParams); if (snd_pcm_hw_params_any (handle, hwParams) < 0) { // this is the error message that aplay returns when an error happens here, // it is a bit more explicit that "Invalid parameter" error = "Broken configuration for this PCM: no configurations available"; return false; } if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0) // works better for plughw.. isInterleaved = true; else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0) isInterleaved = false; else { jassertfalse; return false; } enum { isFloatBit = 1 << 16, isLittleEndianBit = 1 << 17, onlyUseLower24Bits = 1 << 18 }; const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32 | isFloatBit | isLittleEndianBit, SND_PCM_FORMAT_FLOAT_BE, 32 | isFloatBit, SND_PCM_FORMAT_S32_LE, 32 | isLittleEndianBit, SND_PCM_FORMAT_S32_BE, 32, SND_PCM_FORMAT_S24_3LE, 24 | isLittleEndianBit, SND_PCM_FORMAT_S24_3BE, 24, SND_PCM_FORMAT_S24_LE, 32 | isLittleEndianBit | onlyUseLower24Bits, SND_PCM_FORMAT_S16_LE, 16 | isLittleEndianBit, SND_PCM_FORMAT_S16_BE, 16 }; bitDepth = 0; for (int i = 0; i < numElementsInArray (formatsToTry); i += 2) { if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0) { const int type = formatsToTry [i + 1]; bitDepth = type & 255; converter.reset (createConverter (isInput, bitDepth, (type & isFloatBit) != 0, (type & isLittleEndianBit) != 0, (type & onlyUseLower24Bits) != 0, numChannels, isInterleaved)); break; } } if (bitDepth == 0) { error = "device doesn't support a compatible PCM format"; JUCE_ALSA_LOG ("Error: " + error); return false; } int dir = 0; unsigned int periods = 4; snd_pcm_uframes_t samplesPerPeriod = (snd_pcm_uframes_t) bufferSize; if (JUCE_ALSA_FAILED (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0)) || JUCE_ALSA_FAILED (snd_pcm_hw_params_set_channels (handle, hwParams, (unsigned int ) numChannels)) || JUCE_ALSA_FAILED (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir)) || JUCE_ALSA_FAILED (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir)) || JUCE_ALSA_FAILED (snd_pcm_hw_params (handle, hwParams))) { return false; } snd_pcm_uframes_t frames = 0; if (JUCE_ALSA_FAILED (snd_pcm_hw_params_get_period_size (hwParams, &frames, &dir)) || JUCE_ALSA_FAILED (snd_pcm_hw_params_get_periods (hwParams, &periods, &dir))) latency = 0; else latency = (int) frames * ((int) periods - 1); // (this is the method JACK uses to guess the latency..) JUCE_ALSA_LOG ("frames: " << (int) frames << ", periods: " << (int) periods << ", samplesPerPeriod: " << (int) samplesPerPeriod); snd_pcm_sw_params_t* swParams; snd_pcm_sw_params_alloca (&swParams); snd_pcm_uframes_t boundary; if (JUCE_ALSA_FAILED (snd_pcm_sw_params_current (handle, swParams)) || JUCE_ALSA_FAILED (snd_pcm_sw_params_get_boundary (swParams, &boundary)) || JUCE_ALSA_FAILED (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0)) || JUCE_ALSA_FAILED (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary)) || JUCE_ALSA_FAILED (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod)) || JUCE_ALSA_FAILED (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary)) || JUCE_ALSA_FAILED (snd_pcm_sw_params (handle, swParams))) { return false; } #if JUCE_ALSA_LOGGING // enable this to dump the config of the devices that get opened snd_output_t* out; snd_output_stdio_attach (&out, stderr, 0); snd_pcm_hw_params_dump (hwParams, out); snd_pcm_sw_params_dump (swParams, out); #endif numChannelsRunning = numChannels; return true; }
void PatternFormatter::parse() { enum State { LITERAL_STATE, ESCAPE_STATE, MIN_STATE, DOT_STATE, MAX_STATE, CHARACTER_STATE, POSSIBLEOPTION_STATE, OPTION_STATE }; int i = 0; QChar c; char ch; State state = LITERAL_STATE; FormattingInfo formatting_info; QString literal; int converter_start; int option_start; while (i < mPattern.length()) { // i points to the current character // c contains the current character // ch contains the Latin1 equivalent of the current character // i is incremented at the end of the loop to consume the character // continue is used to change state without consuming the character c = mPattern.at(i); ch = c.toLatin1(); switch (state) { case LITERAL_STATE: if (ch == '%') { formatting_info.clear(); converter_start = i; state = ESCAPE_STATE; } else literal += c; break; case ESCAPE_STATE: if (ch == '%') { literal += c; state = LITERAL_STATE; } else if (ch == 'n') { literal += Layout::endOfLine(); state = LITERAL_STATE; } else { if (!literal.isEmpty()) { createLiteralConverter(literal); literal.clear(); } if (ch == '-') formatting_info.mLeftAligned = true; else if (c.isDigit()) { formatting_info.mMinLength = c.digitValue(); state = MIN_STATE; } else if (ch == '.') state = DOT_STATE; else { state = CHARACTER_STATE; continue; } } break; case MIN_STATE: if (!addDigit(c, formatting_info.mMinLength)) { if (ch == '.') state = DOT_STATE; else { state = CHARACTER_STATE; continue; } } break; case DOT_STATE: if (c.isDigit()) { formatting_info.mMaxLength = c.digitValue(); state = MAX_STATE; } else { LogError e = LOG4QT_ERROR(QT_TR_NOOP("Found character '%1' where digit was expected."), LAYOUT_EXPECTED_DIGIT_ERROR, "Log4Qt::PatternFormatter"); e << QString(c); logger()->error(e); } break; case MAX_STATE: if (!addDigit(c, formatting_info.mMaxLength)) { state = CHARACTER_STATE; continue; } break; case CHARACTER_STATE: if (mIgnoreCharacters.indexOf(c) >= 0) state = LITERAL_STATE; else if (mOptionCharacters.indexOf(c) >= 0) state = POSSIBLEOPTION_STATE; else if (mConversionCharacters.indexOf(c) >= 0) { createConverter(c, formatting_info); state = LITERAL_STATE; } else { logger()->warn("Invalid conversion character '%1' at %2 in pattern '%3'", c, i, mPattern); createLiteralConverter(mPattern.mid(converter_start, i - converter_start + 1)); state = LITERAL_STATE; } break; case POSSIBLEOPTION_STATE: if (ch == '{') { option_start = i; state = OPTION_STATE; } else { createConverter(mPattern.at(i - 1), formatting_info); state = LITERAL_STATE; continue; } break; case OPTION_STATE: if (ch == '}') { createConverter(mPattern.at(option_start - 1), formatting_info, mPattern.mid(option_start + 1, i - option_start - 1)); state = LITERAL_STATE; } break; default: Q_ASSERT_X(false, "PatternFormatter::parse()", "Unknown parsing state constant"); state = LITERAL_STATE; } i++; } if (state != LITERAL_STATE) { logger()->warn("Unexptected end of pattern '%1'", mPattern); if (state == ESCAPE_STATE) literal += c; else literal += mPattern.mid(converter_start); } if (!literal.isEmpty()) createLiteralConverter(literal); }
int main(int argc, char* argv[]) { ConvData data; UErrorCode err = U_ZERO_ERROR, localError; char outFileName[UCNV_MAX_FULL_FILE_NAME_LENGTH]; const char* destdir, *arg; size_t destdirlen; char* dot = NULL, *outBasename; char cnvName[UCNV_MAX_FULL_FILE_NAME_LENGTH]; char cnvNameWithPkg[UCNV_MAX_FULL_FILE_NAME_LENGTH]; UVersionInfo icuVersion; UBool printFilename; err = U_ZERO_ERROR; U_MAIN_INIT_ARGS(argc, argv); /* Set up the ICU version number */ u_getVersion(icuVersion); uprv_memcpy(&dataInfo.dataVersion, &icuVersion, sizeof(UVersionInfo)); /* preset then read command line options */ options[OPT_DESTDIR].value=u_getDataDirectory(); argc=u_parseArgs(argc, argv, LENGTHOF(options), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "error in command line argument \"%s\"\n", argv[-argc]); } else if(argc<2) { argc=-1; } if(argc<0 || options[OPT_HELP_H].doesOccur || options[OPT_HELP_QUESTION_MARK].doesOccur) { FILE *stdfile=argc<0 ? stderr : stdout; fprintf(stdfile, "usage: %s [-options] files...\n" "\tread .ucm codepage mapping files and write .cnv files\n" "options:\n" "\t-h or -? or --help this usage text\n" "\t-V or --version show a version message\n" "\t-c or --copyright include a copyright notice\n" "\t-d or --destdir destination directory, followed by the path\n" "\t-v or --verbose Turn on verbose output\n", argv[0]); fprintf(stdfile, "\t --small Generate smaller .cnv files. They will be\n" "\t significantly smaller but may not be compatible with\n" "\t older versions of ICU and will require heap memory\n" "\t allocation when loaded.\n" "\t --ignore-siso-check Use SI/SO other than 0xf/0xe.\n"); return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } if(options[OPT_VERSION].doesOccur) { printf("makeconv version %hu.%hu, ICU tool to read .ucm codepage mapping files and write .cnv files\n", dataInfo.formatVersion[0], dataInfo.formatVersion[1]); printf("%s\n", U_COPYRIGHT_STRING); exit(0); } /* get the options values */ haveCopyright = options[OPT_COPYRIGHT].doesOccur; destdir = options[OPT_DESTDIR].value; VERBOSE = options[OPT_VERBOSE].doesOccur; SMALL = options[OPT_SMALL].doesOccur; if (options[OPT_IGNORE_SISO_CHECK].doesOccur) { IGNORE_SISO_CHECK = TRUE; } if (destdir != NULL && *destdir != 0) { uprv_strcpy(outFileName, destdir); destdirlen = uprv_strlen(destdir); outBasename = outFileName + destdirlen; if (*(outBasename - 1) != U_FILE_SEP_CHAR) { *outBasename++ = U_FILE_SEP_CHAR; ++destdirlen; } } else { destdirlen = 0; outBasename = outFileName; } #if DEBUG { int i; printf("makeconv: processing %d files...\n", argc - 1); for(i=1; i<argc; ++i) { printf("%s ", argv[i]); } printf("\n"); fflush(stdout); } #endif err = U_ZERO_ERROR; printFilename = (UBool) (argc > 2 || VERBOSE); for (++argv; --argc; ++argv) { arg = getLongPathname(*argv); /* Check for potential buffer overflow */ if(strlen(arg) > UCNV_MAX_FULL_FILE_NAME_LENGTH) { fprintf(stderr, "%s\n", u_errorName(U_BUFFER_OVERFLOW_ERROR)); return U_BUFFER_OVERFLOW_ERROR; } /*produces the right destination path for display*/ if (destdirlen != 0) { const char *basename; /* find the last file sepator */ basename = findBasename(arg); uprv_strcpy(outBasename, basename); } else { uprv_strcpy(outFileName, arg); } /*removes the extension if any is found*/ dot = uprv_strrchr(outBasename, '.'); if (dot) { *dot = '\0'; } /* the basename without extension is the converter name */ uprv_strcpy(cnvName, outBasename); /*Adds the target extension*/ uprv_strcat(outBasename, CONVERTER_FILE_EXTENSION); #if DEBUG printf("makeconv: processing %s ...\n", arg); fflush(stdout); #endif localError = U_ZERO_ERROR; initConvData(&data); createConverter(&data, arg, &localError); if (U_FAILURE(localError)) { /* if an error is found, print out an error msg and keep going */ fprintf(stderr, "Error creating converter for \"%s\" file for \"%s\" (%s)\n", outFileName, arg, u_errorName(localError)); if(U_SUCCESS(err)) { err = localError; } } else { /* Insure the static data name matches the file name */ /* Changed to ignore directory and only compare base name LDH 1/2/08*/ char *p; p = strrchr(cnvName, U_FILE_SEP_CHAR); /* Find last file separator */ if(p == NULL) /* OK, try alternate */ { p = strrchr(cnvName, U_FILE_ALT_SEP_CHAR); if(p == NULL) { p=cnvName; /* If no separators, no problem */ } } else { p++; /* If found separtor, don't include it in compare */ } if(uprv_stricmp(p,data.staticData.name)) { fprintf(stderr, "Warning: %s%s claims to be '%s'\n", cnvName, CONVERTER_FILE_EXTENSION, data.staticData.name); } uprv_strcpy((char*)data.staticData.name, cnvName); if(!uprv_isInvariantString((char*)data.staticData.name, -1)) { fprintf(stderr, "Error: A converter name must contain only invariant characters.\n" "%s is not a valid converter name.\n", data.staticData.name); if(U_SUCCESS(err)) { err = U_INVALID_TABLE_FORMAT; } } uprv_strcpy(cnvNameWithPkg, cnvName); localError = U_ZERO_ERROR; writeConverterData(&data, cnvNameWithPkg, destdir, &localError); if(U_FAILURE(localError)) { /* if an error is found, print out an error msg and keep going*/ fprintf(stderr, "Error writing \"%s\" file for \"%s\" (%s)\n", outFileName, arg, u_errorName(localError)); if(U_SUCCESS(err)) { err = localError; } } else if (printFilename) { puts(outBasename); } } fflush(stdout); fflush(stderr); cleanupConvData(&data); } return err; }
shared_ptr<ZLEncodingConverter> DummyEncodingConverterProvider::createConverter(const std::string&) { return createConverter(); }
bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize) { if (handle == 0) return false; snd_pcm_hw_params_t* hwParams; snd_pcm_hw_params_alloca (&hwParams); if (failed (snd_pcm_hw_params_any (handle, hwParams))) return false; if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0) isInterleaved = false; else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0) isInterleaved = true; else { jassertfalse; return false; } enum { isFloatBit = 1 << 16, isLittleEndianBit = 1 << 17 }; const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32 | isFloatBit | isLittleEndianBit, SND_PCM_FORMAT_FLOAT_BE, 32 | isFloatBit, SND_PCM_FORMAT_S32_LE, 32 | isLittleEndianBit, SND_PCM_FORMAT_S32_BE, 32, SND_PCM_FORMAT_S24_3LE, 24 | isLittleEndianBit, SND_PCM_FORMAT_S24_3BE, 24, SND_PCM_FORMAT_S16_LE, 16 | isLittleEndianBit, SND_PCM_FORMAT_S16_BE, 16 }; bitDepth = 0; for (int i = 0; i < numElementsInArray (formatsToTry); i += 2) { if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0) { bitDepth = formatsToTry [i + 1] & 255; const bool isFloat = (formatsToTry [i + 1] & isFloatBit) != 0; const bool isLittleEndian = (formatsToTry [i + 1] & isLittleEndianBit) != 0; converter = createConverter (isInput, bitDepth, isFloat, isLittleEndian, numChannels); break; } } if (bitDepth == 0) { error = "device doesn't support a compatible PCM format"; DBG ("ALSA error: " + error + "\n"); return false; } int dir = 0; unsigned int periods = 4; snd_pcm_uframes_t samplesPerPeriod = bufferSize; if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0)) || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels)) || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir)) || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir)) || failed (snd_pcm_hw_params (handle, hwParams))) { return false; } snd_pcm_uframes_t frames = 0; if (failed (snd_pcm_hw_params_get_period_size (hwParams, &frames, &dir)) || failed (snd_pcm_hw_params_get_periods (hwParams, &periods, &dir))) latency = 0; else latency = frames * (periods - 1); // (this is the method JACK uses to guess the latency..) snd_pcm_sw_params_t* swParams; snd_pcm_sw_params_alloca (&swParams); snd_pcm_uframes_t boundary; if (failed (snd_pcm_sw_params_current (handle, swParams)) || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary)) || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0)) || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary)) || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod)) || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary)) || failed (snd_pcm_sw_params (handle, swParams))) { return false; } #if 0 // enable this to dump the config of the devices that get opened snd_output_t* out; snd_output_stdio_attach (&out, stderr, 0); snd_pcm_hw_params_dump (hwParams, out); snd_pcm_sw_params_dump (swParams, out); #endif numChannelsRunning = numChannels; return true; }